DapperLib / DapperLib/Dapper

Query<DateOnly> / Query<TimeOnly> (scalar form) silently return default(T)

Open
#2,227 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

Found while probing #2226, but this one is independent of provider and Npgsql version — and it is silent, which makes it the more serious of the two.

With Dapper 2.1.72, a single-column query materialized as a bare DateOnly/TimeOnly returns the default value with no error:

probe result
QuerySingle<DateOnly>("select '2021-01-01'::date") (Npgsql 9 and 10) 0001-01-01 ❌ silent
QuerySingle<DateOnly>("select cast('2021-01-01' as date)") (SqlClient) 0001-01-01 ❌ silent
QuerySingle<TimeOnly>("select '03:03:03'::time") (Npgsql) 00:00 ❌ silent
ExecuteScalar<DateOnly>("select '2021-01-01'::date") (Npgsql) 2021-01-01
POCO with a DateOnly member (Npgsql 10) 2021-01-01

ExecuteScalar<DateOnly> and the member path are fine, so this looks like the Query<T> simple-vs-complex type decision not recognising DateOnly/TimeOnly as scalar types (Type.GetTypeCode reports Object for both) — the member-mapping deserializer then finds nothing to bind on a struct with no settable members and hands back a default instance. The type map entries added in #2051 (DoNotSetFieldValue/UseGetFieldValue) apparently don't reach this decision.

Wrong data with no exception is the worst failure mode available, so flagging it separately from #2226 rather than folding it in.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Query simple-versus-complex type decision and compare it with the working ExecuteScalar and POCO member paths. Check how the type-map entries from #2051 participate in that decision, then add regression coverage showing DateOnly and TimeOnly scalar queries return their database values rather than default instances.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
backend-api-design, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.