You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Null check is wrongly dropped for NodaTime.Interval.Start and NodaTime.Interval.End with efcore linq2sql #3585
The expression e.Duration.End == null is wrongly assumed to be always false because Interval.End is non nullable and it is dropped from the resulting SQL:
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed bug in the Npgsql NodaTime range-bound translation. With a non-null Duration whose upper bound is unbounded, the reported query returns 0 rows instead of 1. Explicitly projecting End as Instant? does not prevent this. I also reproduced the equivalent problem for an unbounded Start.
On the reported Npgsql 9.0.4 / EF Core 9.0.7 combination, this generates:
SELECTupper(e."Duration")::timestamptzAS"End"FROM"Events"AS e
WHERE FALSE
The predicate should instead retain upper(e."Duration") IS NULL: PostgreSQL's upper() returns null for an unbounded upper bound even when the range itself is not null.
Version comparison: the reduced query returned 0 instead of 1 in each of these combinations, using PostgreSQL 18.4:
Npgsql provider and NodaTime plugin
EF Core / Relational
8.0.0
8.0.0
9.0.3
9.0.7
9.0.4
9.0.7
10.0.3
10.0.4
11.0.0-rc.1.1
11.0.0-rc.1.26425.128
This is not newly introduced in 9.0.4 or EF Core 9; it is already present in 8.0.0. No previously working version was identified. It remains reproducible in the latest stable and prerelease NodaTime packages available when checked.
Likely cause: both Lower() and Upper() in NpgsqlNodaTimeMemberTranslator.TranslateInterval specify nullable: true but also argumentsPropagateNullability: TrueArrays[1]. That propagation metadata permits EF to replace a bound's null check with a null check on the range argument. Since Duration is required, that becomes false. These functions can also return null for a non-null range, so their argument-propagation entries should be false while retaining nullable: true.
The reported HasEnd ? End : null workaround was also checked and returned the expected row.
Provider scope and related issues: this points to Npgsql's PostgreSQL-specific range translation, rather than a general EF Core bug. A direct SQLite comparison stops at model validation because SQLite does not support the Interval mapping. No exact duplicate was found in the EF Core or Npgsql issue searches. Related background: dotnet/efcore#23042 explains why functions that can return null with non-null arguments must not opt into this null-propagation optimization; it is not a duplicate report of this NodaTime bug.
minimal repro
This translation-only repro needs no database or seed data. The wrong-result behavior above was separately confirmed by executing against a database containing one event with new Interval(Instant.FromUtc(2025, 1, 1, 0, 0), null).
Use a net8.0 console project with these package references:
usingSystem;usingSystem.Linq;usingMicrosoft.EntityFrameworkCore;usingMicrosoft.Extensions.Logging;usingNodaTime;awaitusingvarcontext=newAppDbContext();Console.WriteLine(context.Events.Select(e =>new{End=(Instant?)e.Duration.End}).Where(p =>p.End==null).ToQueryString());publicclassAppDbContext:DbContext{publicDbSet<Event>Events{get;set;}protectedoverridevoidOnConfiguring(DbContextOptionsBuilderoptionsBuilder)=>optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("Test__Npgsql__DefaultConnection"),
o =>o.UseNodaTime()).LogTo(Console.WriteLine,LogLevel.Information).EnableSensitiveDataLogging();}publicclassEvent{publicintId{get;set;}publicIntervalDuration{get;set;}}
changed the title [-]null check is wrongly dropped for NodaTime.Interval.Start and NodaTime.Interval.End with efcore linq2sql[/-][+]Null check is wrongly dropped for NodaTime.Interval.Start and NodaTime.Interval.End with efcore linq2sql[/+]on Oct 18, 2026
Activity
roji commentedon Oct 17, 2026
AI Triage
The below is an AI-generated analysis and may contain inaccuracies.
Confirmed bug in the Npgsql NodaTime range-bound translation. With a non-null
Durationwhose upper bound is unbounded, the reported query returns 0 rows instead of 1. Explicitly projectingEndasInstant?does not prevent this. I also reproduced the equivalent problem for an unboundedStart.The query can be reduced to:
On the reported Npgsql 9.0.4 / EF Core 9.0.7 combination, this generates:
The predicate should instead retain
upper(e."Duration") IS NULL: PostgreSQL'supper()returns null for an unbounded upper bound even when the range itself is not null.Version comparison: the reduced query returned 0 instead of 1 in each of these combinations, using PostgreSQL 18.4:
This is not newly introduced in 9.0.4 or EF Core 9; it is already present in 8.0.0. No previously working version was identified. It remains reproducible in the latest stable and prerelease NodaTime packages available when checked.
Likely cause: both
Lower()andUpper()inNpgsqlNodaTimeMemberTranslator.TranslateIntervalspecifynullable: truebut alsoargumentsPropagateNullability: TrueArrays[1]. That propagation metadata permits EF to replace a bound's null check with a null check on the range argument. SinceDurationis required, that becomes false. These functions can also return null for a non-null range, so their argument-propagation entries should be false while retainingnullable: true.The reported
HasEnd ? End : nullworkaround was also checked and returned the expected row.Provider scope and related issues: this points to Npgsql's PostgreSQL-specific range translation, rather than a general EF Core bug. A direct SQLite comparison stops at model validation because SQLite does not support the
Intervalmapping. No exact duplicate was found in the EF Core or Npgsql issue searches. Related background: dotnet/efcore#23042 explains why functions that can return null with non-null arguments must not opt into this null-propagation optimization; it is not a duplicate report of this NodaTime bug.minimal repro
This translation-only repro needs no database or seed data. The wrong-result behavior above was separately confirmed by executing against a database containing one event with
new Interval(Instant.FromUtc(2025, 1, 1, 0, 0), null).Use a
net8.0console project with these package references:[10.0] Fix null checks on unbounded NodaTime Interval bounds (#4002)
[9.0] Fix null checks on unbounded NodaTime Interval bounds (#4004)
[8.0] Fix null checks on unbounded NodaTime Interval bounds (#4003)
[-]null check is wrongly dropped for NodaTime.Interval.Start and NodaTime.Interval.End with efcore linq2sql[/-][+]Null check is wrongly dropped for NodaTime.Interval.Start and NodaTime.Interval.End with efcore linq2sql[/+]