Skip to content

fix: a range factory over a NULL element is NULL in a query (#382) - #392

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/382-factories-over-null
Oct 24, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/382-factories-over-null

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

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, CreateUnboundedStart and CreateUnboundedEnd built 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.

  • CreateFinite fell into its inverted-bounds guard and gave empty.
  • The unbounded factories passed the NULL to PostgreSQL's range constructor. It reads a NULL bound as unbounded, so the result was (,).

So even a positive filter selected a row with no element: DateRange.CreateUnboundedEnd(b.Visit!.From).Contains(v) was true for 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, because daterange(NULL, NULL, '[)') IS NOT NULL is true.

Change

  • In ValueRangesMethodCallTranslator, each factory is now wrapped by NullOverNullElement: 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. For CreateFinite, EF Core merges the two CASEs into one.
  • The six #382 candidates from OuterJoinProbeTests reported candidate fixed and are removed.
  • Docs: a sentence in the factory bullet of docs/efcore.md. Claim E04 quotes it, and NullOperandTranslationTests and OuterJoinProbeTests now hold it. There's also a row and a sentence in docs/migration.md#check-predicates-over-a-null-range-or-a-null-column.
  • Changelogs: a ### Breaking row under 11.0.0-preview.1 in the root, EF Core and EF Core NodaTime changelogs.

Tests

  • NullOperandTranslationTests.ARangeFactoryOverANullableElement_IsNull pins five statements:

    • three factories over a nullable Day, used as Contains, == null and IsEmpty();
    • two over required elements, whose SQL is unchanged.

    With the fix stripped, it fails with actual: "daterange(r.\"Day\", NULL, '[)') IS NOT NULL AND …".

  • Live, on PostgreSQL 16: OuterJoinProbeTests fails with exactly six candidate fixed entries, 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

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]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Oct 24, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working silent Answers wrongly without throwing — fixes go in the next major, never deferred found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/ranges Range unions, variants and the shape engines package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime severity/medium Inconsistency or failure in a narrow scenario stacked Base is another open PR; merge in order, CI does not run until it targets main labels Oct 24, 2026
Base automatically changed from fix/381-null-element-contains to main October 24, 2026 20:43
@CaffeinatedCoder
CaffeinatedCoder merged commit 5bdcf49 into main Oct 24, 2026
11 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/382-factories-over-null branch October 24, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ranges Range unions, variants and the shape engines bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime severity/medium Inconsistency or failure in a narrow scenario silent Answers wrongly without throwing — fixes go in the next major, never deferred stacked Base is another open PR; merge in order, CI does not run until it targets main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The range factories over a NULL element build a range: CreateFinite gives empty and CreateUnboundedStart/End give (,), where EF Core answers NULL

1 participant