Skip to content

CommandUtils.As<DateTime> throws on a DateOnly source (Npgsql 10 'date' columns) #202

Description

@mgravell

DateOnlyTimeOnlyPostgreSqlTests.ReadDateOnly fails on main with:

System.InvalidCastException: Unable to cast object of type 'System.DateOnly' to type 'System.IConvertible'
   at System.Convert.ToDateTime(Object value, IFormatProvider provider)

Cause: Npgsql 10 changed the default reader.GetValue() mapping for date columns from DateTime to DateOnly (the test's own comment — "DbReader will return DateTime here" — documents the old world). CommandUtils.As<T>'s DateTime/DateTime? branches fall through to Convert.ToDateTime, and DateOnly doesn't implement IConvertible. The As<TimeOnly>-from-date assertion in the same test would hit the identical wall one line later.

Bisected empirically: with everything else identical, the test passes on Npgsql 9.0.2 and fails on 10.0.2; the bump landed in #174 (May 2026). Nobody saw it because the Postgres integration tests need local Docker, which CI doesn't provide — the whole class was unmeasured, not green.

Fix shape: teach As<T> about a DateOnly source — As<DateTime[?]> via ToDateTime(TimeOnly.MinValue), and As<TimeOnly[?]> returning default (matching the test's documented "no time in the actual data" contract). Plus direct unit tests on CommandUtils.As so the coverage doesn't depend on Docker being up.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions