Repository navigation
fix: a predicate over a null range, range set or value set is false - #371
Merged
Merged
Conversation
…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]>
This was referenced Oct 24, 2026
CaffeinatedCoder
enabled auto-merge
October 24, 2026 16:29
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 #355
Refs #350
Rule (c), decided on #350: a Boolean predicate with a
nullrange, range set or value set on either side isfalse, and its negationtrue, in memory and in SQL. This PR is the predicate half formain. #350 stays open for its 11.0.0-only value-producing half (ArgumentNullExceptionfromIntersect,Gap,Merge,Union,Except). The 10.x port is #357.Problem
In SQL (#355): a predicate over a NULL column was NULL, so a filter dropped the row whether the predicate was negated or not. EF Core's own translations treat a predicate over NULL as
falseand keep the row under a negation (!b.Name.StartsWith("a")→NOT LIKE … OR "Name" IS NULL;string[]alike). The package even disagreed with itself: a value set's!IsEmptykept the NULL row, its!Containsdropped it. A projected predicate over a NULL row threwInvalidOperationExceptionwhen read intobool.In memory (#350): a null range answered most predicates
false, but not all.Contains(Empty),IsContainedBy((,))and(,).Contains(null)returnedtrue.Contains(T)threw, and so did a nullRangeSetoperand.RangeSet's own predicates threw or returnedtruefor a null operand. In total, 1105 calls across the 13 range types didn't answerfalse.Change
RangeExtensionsandRangeSet: a null guard on every predicate that didn't already answerfalse. Block bodies get a first statement, expression bodiesx is not null && …, and the members that delegate toRangeSetinherit its guard. Value set predicates keep their deliberate contract: they throw for a null set (ThrowIfNull(other); a null receiver fails onValues).Translatewraps everybooltranslation withx IS NOT NULL AND <predicate>, for each range, multirange or value set operand (FalseOverNull). EF Core's nullability processing drops the check for a required column and a non-null parameter, and writesx IS NULL OR NOT (…)under a negation. That shape was measured identical on EF Core 11 RC, 10.0.0 and 10.0.13 with Npgsql 10.0.3, in A predicate over a NULL range, RangeSet or value set column is NULL in SQL, so its negation drops the row EF Core's own translations keep #355.CompareTonever reaches the translator: EF Core rewrites it into a comparison and A NULL range column now matches CompareTo(null) > 0 in a query; Comparer treats null vs null as equal #261's rule applies. Equality is EF Core's own.w."Value" IS NOT NULL AND, because EF Core treats aVALUESorWHERE FALSEelement column as nullable; anullin the list now answersfalsein SQL as in memory.docs/ranges.md(under "Ask questions about a range") anddocs/efcore.md(under "Query ranges with LINQ"): the rule, quoted by claims R49 and E71.docs/migration.md: a bullet and### Check predicates over a null range or a NULL columnunder## Migration from v10.x, with before/after tables for memory and SQL.Ranges:line (root, core) and anEF Core:line (root, EF Core, EF Core NodaTime) under### Breakingin[11.0.0-preview.1].test/oracles/candidates.json: A null range answers some extensions in memory and throws on others, and the answers it gives disagree with PostgreSQL on a NULL column #350's seven predicate candidates reportedcandidate fixedand are removed. Its four value-producing ones stay for the 11.0.0 half.Tests
Local, SDK
11.0.100-rc.2.26504.105, Docker (OrbStack).RangeNullPredicateContractTests(conventions, new, registered as an oracle): it discovers every publicboolmember ofRangeExtensionsfor every range type of both libraries, and every BooleanRangeSetinstance member taking a range or set. It calls each withnullon either side and both, against every shape and set probe. Before the change, 1105 calls failed; now none do. Seed:range-predicate-answers-on-a-null.patch.ExecutedQueryTests.EveryPredicate_OverANullableColumn_IsFalseForTheNullRow(new): it discovers everyboolpredicate ofRangeExtensions,RangeSetandValueSetExtensions, about 140 that translate. Each runs over a nullableDateRange,RangeSet<DateRange, DateOnly>andStringSetcolumn, with the column on either side, asWhere(f),Where(!f)andSelect(f), against memory over the loaded rows. Where memory throws on the NULL row, the expected answer isfalse. Seedsrange-predicate-over-a-null-column-is-null.patchandvalue-set-predicate-over-a-null-column-is-null.patch, each the wrapper removed from one translator; with them the sweep fails on 175 and 21 results.NullOperandTranslationTests(new) pins the SQL: a required column unchanged (NOT (r."Period" && @window)), and a nullable range, multirange and value set column withIS NULL OR NOT (…),IS NOT NULL AND …and the projection.PredicatesOverANullableColumn_SelectTheRowsMemorySelects(from test: register #349 and #350 as ExecutedQueryTests candidates #352) reported exactly A null range answers some extensions in memory and throws on others, and the answers it gives disagree with PostgreSQL on a NULL column #350's seven predicate candidates fixed, and nothing else.range-against-set-reads-first-element-for-upper-bound.patchis refreshed, its context taking the new guard, and both its oracles still catch it. Every seed that patches a changed file applies and is caught (dotnet run tools/oracles.cs seeds, listed in the run below).postgres:16-alpine: all eight projects pass (core 1399, NodaTime 239, EF 297, EF NodaTime 83, ASP.NET Core 92, conventions 409, integration 288, infinity-disabled 4).🤖 Generated with Claude Code