Repository navigation
fix: a range factory over a NULL element is NULL in a query (#382) - #392
Merged
Merged
Conversation
CreateFinite fell into its inverted-bounds guard and gave empty, and CreateUnboundedStart/End passed the NULL to PostgreSQL's range constructor, which reads a NULL bound as unbounded and gave (,). So Contains(v) was true for a row without the element: the optional side of an outer join, or a nullable column read with .Value. The factories are now CASE WHEN e IS NULL THEN NULL ELSE <translation> END, which EF Core folds away for required elements, non-null parameters and constants. Found-By: OT Defect-Class: SQL Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #382
Stacked on PR #391 (#381). Merge that one first; this PR's diff is its own commit.
Problem
Over a NULL element,
CreateFinite,CreateUnboundedStartandCreateUnboundedEndbuilt a range in a query instead of NULL. An element is NULL on the optional side of an outer join, or when a nullable column is read with.Value.CreateFinitefell into its inverted-bounds guard and gaveempty.(,).So even a positive filter selected a row with no element:
DateRange.CreateUnboundedEnd(b.Visit!.From).Contains(v)wastruefor a booking without a visit. EF Core answers NULL for its own value-producing members (b.Visit!.From.AddDays(1)). Rule (c)'s predicate wrapper couldn't help, becausedaterange(NULL, NULL, '[)') IS NOT NULListrue.Change
ValueRangesMethodCallTranslator, each factory is now wrapped byNullOverNullElement:CASE WHEN e IS NULL [OR f IS NULL] THEN NULL ELSE <today's translation> END. For required columns, non-null parameters and constants, EF Core's nullability processing folds the test away, so their SQL is what it was. ForCreateFinite, EF Core merges the twoCASEs into one.#382candidates fromOuterJoinProbeTestsreportedcandidate fixedand are removed.docs/efcore.md. Claim E04 quotes it, andNullOperandTranslationTestsandOuterJoinProbeTestsnow hold it. There's also a row and a sentence indocs/migration.md#check-predicates-over-a-null-range-or-a-null-column.### Breakingrow under11.0.0-preview.1in the root, EF Core and EF Core NodaTime changelogs.Tests
NullOperandTranslationTests.ARangeFactoryOverANullableElement_IsNullpins five statements:Day, used asContains,== nullandIsEmpty();With the fix stripped, it fails with
actual: "daterange(r.\"Day\", NULL, '[)') IS NOT NULL AND …".Live, on PostgreSQL 16:
OuterJoinProbeTestsfails with exactly sixcandidate fixedentries, and passes once they're removed. The whole integration project passes (300 tests), and so does InfinityDisabled.Translation (EF, EF NodaTime), AspNetCore and conventions suites pass.
Every seed that patches the translator still applies.
The 10.x port is #388, for 10.2.0 (#358).
🤖 Generated with Claude Code