Dates in $filter parsed as DateTime with DateTimeKind.Unspecified
2002Ezio opened this issue · 1 comments
I'm working on the breakdance-net5, with the latest postgres provider.
Npgsql 6.0 has a breaking change around timestamp mapping which breaks querying via OData. In order to query a Postgres column of type 'timestamp with time zone', the corresponding DateTime needs to have Kind = DateTimeKind.Utc.
However, all dates in the $filter clause are parsed with DateTimeKind.Unspecified, which causes Npgsql to throw an exception and results in OData returning an invalid and incomplete JSON response.
Setting builder.Select().Expand().Filter().OrderBy().MaxTop(100).Count().SetTimeZoneInfo(TimeZoneInfo.Utc);
Assemblies affected
This behavior is observed using the latest bits in the branch titled "breakdance-net5"
Reproduce steps
Uses a postgres data base with the latest npgsql provider and try to filter an entity by date and time
https://localhost:44307/v_errorlog?$orderby=datetimeinlocaltime desc&$top=10&$filter=(datetimeinlocaltime ge 2022-03-10T16:43:00Z) and (datetimeinlocaltime lt 2022-03-10T16:44:00Z)&$count=true
Actual Result
write DateTime with Kind=Unspecified to PostgreSQL type 'timestamp with time zone', only UTC is supported. Note that it's not possible to mix DateTimes with different Kinds in an array/range. See the Npgsql.EnableLegacyTimestampBehavior AppContext switch to enable legacy behavior.