Skip to content

fix: a predicate over a null range, range set or value set is false (10.x, port of #355, #356 and #350's predicate half) - #373

Merged
CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/357-null-predicates-10.x
Oct 24, 2026
Merged

CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/357-null-predicates-10.x

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #357

The 10.x port of the predicate half of rule (c) for 10.2.0 (#358): git cherry-pick -x of #370's commit (f4f05dd, #356) and #371's commit (8bd0048, #355 with #350's predicate half), both merged into main. Against release/10.x the closing keyword closes nothing, so #357 is closed by hand after the merge.

Problem

10.1.0 has every defect the two main PRs fix:

  • A null range in a range set: RangeSet.From stored it, and Except and Union on a null range built such a set.
  • Predicates on a null range: some answered true in memory (Contains(Empty), IsContainedBy((,)), (,).Contains(null)), and some threw (Contains(T), a null set operand, RangeSet's own predicates).
  • Predicates over a NULL column: NULL in SQL, so a negated filter dropped the row that EF Core keeps for its own types, and a projected predicate threw.

Change

Tests

Local, SDK 10.0.402, Docker:

  • Full suite, EF Core 10.0.0 floor, postgres:16-alpine: all eight projects pass (core 1399, NodaTime 239, EF 309, EF NodaTime 91, ASP.NET Core 92, conventions 408, integration 284, infinity-disabled 4).
  • EF Core 10.0.13 with Npgsql 10.0.3 (-p:EfFloat=10.0.13 -p:NpgsqlEfFloat=10.0.3, versions confirmed in deps.json): translation 309/309 and integration 284/284. The captured-list pins hold on both EF shapes.
  • ExecutedQueryTests on postgres:18-alpine: 16/16.
  • Seeds: dotnet run tools/oracles.cs seeds on this branch, for the four new seeds (the reverts of this port) and every seed that patches RangeSet.cs, RangeExtensions.cs or either method-call translator. All apply and are caught (run below).

🤖 Generated with Claude Code

CaffeinatedCoder and others added 2 commits October 24, 2026 18:34
RangeSet.From, the collection-expression builder RangeSet.Create, and through
them Union and Except called on a null range, built a set whose one element was
null: Count 1, IsEmpty() false, Equals(Empty) false, and the first Contains threw
NullReferenceException. With two or more inputs From threw while sorting, and
next to (,) the null was ignored, because the loop returned at the first infinity.

Both normalize loops and the single-element fast path now throw
ArgumentException ("A range set cannot contain a null range.", ranges) for a null
anywhere in the input, reading every input after an infinity too. That is the
value sets' rule: a null element refused with ArgumentException, never dropped,
because a null range is not an empty one.

RangeSetNullContractTests (conventions, registered as an exception oracle beside
ValueSetNullContractTests) discovers every range type of both libraries and puts
the null first, after a bounded, the empty and the infinite range, through both
From overloads and Create, plus Union and Except on a null range. Its seed
rangeset-stores-a-null-range.patch is caught. Claim M18 quotes the new
docs/ranges.md sentence. #350's Union(Infinite).Contains(v) candidate reports
fixed, since memory now throws for it, and is removed.

Found-By: CA
Defect-Class: CAN

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit f4f05dd)
…355, #350)

Rule (c) from #350, the predicate half: a Boolean predicate with a null range,
range set or value set on either side is false, and its negation true, in memory
and in SQL, as EF Core answers for its own types.

Memory: null guards on every RangeExtensions and RangeSet predicate that did not
already answer false. Contains(Empty), IsContainedBy((,)) and (,).Contains(null)
returned true; Contains(T), a null RangeSet operand and RangeSet's own predicates
with a null operand threw. Value set predicates keep throwing for a null set.

SQL: both method-call translators wrap every bool translation as
x IS NOT NULL AND <predicate> for each range, multirange or value set operand.
EF Core drops the check for a required column and a non-null parameter and
writes x IS NULL OR NOT (...) under a negation, so a negated predicate keeps the
NULL row and a projected one reads false. CompareTo never reaches the
translator, and equality is EF Core's own.

RangeNullPredicateContractTests (new oracle) and
ExecutedQueryTests.EveryPredicate_OverANullableColumn_IsFalseForTheNullRow
discover every predicate; three seeds keep the reverts. #350's seven predicate
candidates are removed as fixed. NullOperandTranslationTests pins the SQL; the
captured-list pins gain the list element's null check. Claims R49 and E71.

Found-By: US
Defect-Class: SQL

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 8bd0048)
@CaffeinatedCoder CaffeinatedCoder added this to the 10.2.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 breaking Changes an answer or a signature — needs a major area/ranges Range unions, variants and the shape engines area/range-set RangeSet and multirange algebra area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/core Affects CodoMetis.ValueRanges package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime severity/medium Inconsistency or failure in a narrow scenario labels Oct 24, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit d1180c5 into release/10.x Oct 24, 2026
10 of 13 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/357-null-predicates-10.x branch October 24, 2026 16:44
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 area/value-sets Value set families and wrapper arities breaking Changes an answer or a signature — needs a major bug Something isn't working package/core Affects CodoMetis.ValueRanges 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant