Npgsql 10.0 compatibility: DATE columns throw InvalidCastException due to DateOnly default mapping change

Aperta
#869 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
58/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
postgresql
Ambito
databases

Direzione di ricerca

Inizia con la riproduzione in F# dell’issue usando PostgreSQL 15.12, Npgsql 10.0.1 e SQLProvider.PostgreSql 1.5.17. Traccia il percorso del provider PostgreSQL che chiama NpgsqlDataReader.GetDateTime() durante la lettura di una colonna date. Il lavoro è completato quando la query legge il valore date senza InvalidCastException con Npgsql 10.0, e il comportamento interessato è coperto da un test di regressione appropriato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

postgresql

Describe the bug

SQLProvider is incompatible with Npgsql 10.0, which changed the default .NET mapping for PostgreSQL date columns from System.DateTime to System.DateOnly (and time from TimeSpan to TimeOnly).

To Reproduce

CREATE TABLE test (
    id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
    d DATE NOT NULL
);
INSERT INTO test (d) VALUES ('2024-01-28');
open FSharp.Data.Sql.PostgreSql
open FSharp.Data.Sql.Common

type Db = SqlDataProvider<
  DatabaseProviderTypes.POSTGRESQL,
  "Host=localhost;Database=test;Username=postgres;Password=test">
let ctx = Db.GetDataContext()
for row in query { for r in ctx.Public.Test do select r } do
    printfn "%A" row.D   // throws InvalidCastException with Npgsql 10

Environment (please complete the following information):

  • PostgreSQL v15.12
<PackageReference Include="Npgsql" Version="10.0.1" />
<PackageReference Include="SQLProvider.PostgreSql" Version="1.5.17" />

Additional context

This is from an analysis by Claude.

SQLProvider's PostgreSQL provider internally calls GetDateTime() on the NpgsqlDataReader when reading date columns. In Npgsql 10.0, this throws an InvalidCastException at runtime because the reader now returns DateOnly by default for date columns.

The build succeeds because SQLProvider's type mapping is resolved at design time independently of Npgsql's runtime behavior. The failure only surfaces at runtime when rows are actually read.

Workaround

Apply the Npgsql 10.0 legacy behavior opt-out via AppContext switch as documented in the Npgsql 10.0 release notes.

Additional References

Lingua principale
F#
Stelle
627
Fork
147
Merge medio
2h 2m
PR unite (30g)
1

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fsprojects/SQLProvider

Tutte le issue di fsprojects/SQLProvider

Issue simili

Altre issue su Databases

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.