Skip to content

fix: Contains(T) over a NULL element is false in a query (#381) - #391

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/381-null-element-contains
Oct 24, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/381-null-element-contains

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #381

Problem

Rule (c) (#350, #355) guarded a NULL range, multirange or value set operand, but not the element of Contains(T). An element is NULL on the optional side of an outer join, or when a nullable column is read with .Value. Then r."Period" @> e was NULL, with three consequences:

  • !b.Period.Contains(b.Visit!.On) dropped the row. EF Core keeps that row for its own comparisons.
  • Select(b => b.Period.Contains(b.Visit!.On)) threw InvalidOperationException.
  • list.All(x => x.Contains(r.Day!.Value)) over a non-empty captured list selected the NULL rows.

Change

  • ValueRangesMethodCallTranslator.FalseOverNull now also wraps an operand of the range's element type, as e IS NOT NULL AND <predicate>. For a required element, a non-null parameter or a constant, EF Core's nullability processing drops the check, so that SQL is unchanged. Under a negation it writes e IS NULL OR NOT (…).
  • The 14 #381 candidates in test/oracles/candidates.json reported candidate fixed and are removed: 2 from OuterJoinProbeTests, 6 from NullableOperandPairProbeTests and 6 from QuantifierProbeTests.
  • Docs: docs/efcore.md (rule (c) paragraph) and docs/migration.md#check-predicates-over-a-null-range-or-a-null-column (two rows and a sentence). Claim E71 now names the element.
  • Changelogs: a ### Breaking row under 11.0.0-preview.1 in the root, EF Core and EF Core NodaTime changelogs. It goes there because a silent fix on main goes under Breaking before 11.0.0.

Tests

  • NullOperandTranslationTests.ANullableElement_IsCheckedForNull pins the SQL for a nullable element (positive, negated, and on a nullable RangeSet) and for a required one, which is unchanged. With the fix stripped, it fails with actual: "r.\"Period\" @> r.\"Day\"".
  • Live, on PostgreSQL 16: the three probe classes fail with exactly 14 candidate fixed entries and nothing else, and pass once the entries are removed. The whole integration project passes (300 tests), and so does InfinityDisabled.
  • Translation (EF, EF NodaTime), AspNetCore and conventions suites pass.
  • Seed range-predicate-over-a-null-column-is-null still applies and is still caught by five oracles (tools/oracles.cs seeds).

The 10.x port is #387, for 10.2.0 (#358). #382 is stacked on this PR, because it changes the same translator, changelogs and candidates file.

🤖 Generated with Claude Code

Rule (c) guarded a NULL range, multirange or value set operand, but not
the element. Over the optional side of an outer join, or a nullable
column read with .Value, r."Period" @> e was NULL: the negation dropped
the row EF Core keeps for its own comparisons, a projection into bool
threw, and All over a captured list selected the NULL rows. The
predicate wrapper now checks the element too (e IS NOT NULL AND ...);
EF Core drops the check for a required element.

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 area/range-set RangeSet and multirange algebra package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime severity/low Cosmetic, message or documentation-level difference labels Oct 24, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 393bafa into main Oct 24, 2026
11 of 14 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/381-null-element-contains branch October 24, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/range-set RangeSet and multirange algebra 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/low Cosmetic, message or documentation-level difference silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Contains(element) on a range or RangeSet is NULL in SQL for a NULL element: the negation drops the row EF Core keeps, and a projection into bool throws

1 participant