Repository navigation
fix: Contains(T) over a NULL element is false in a query (#381) - #391
Merged
Merged
Conversation
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]>
This was referenced Oct 24, 2026
10.x: Contains(element) on a range or RangeSet is NULL in SQL for a NULL element (port of #381)
#387
Closed
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 #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. Thenr."Period" @> ewas 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))threwInvalidOperationException.list.All(x => x.Contains(r.Day!.Value))over a non-empty captured list selected the NULL rows.Change
ValueRangesMethodCallTranslator.FalseOverNullnow also wraps an operand of the range's element type, ase 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 writese IS NULL OR NOT (…).#381candidates intest/oracles/candidates.jsonreportedcandidate fixedand are removed: 2 fromOuterJoinProbeTests, 6 fromNullableOperandPairProbeTestsand 6 fromQuantifierProbeTests.docs/efcore.md(rule (c) paragraph) anddocs/migration.md#check-predicates-over-a-null-range-or-a-null-column(two rows and a sentence). Claim E71 now names the element.### Breakingrow under11.0.0-preview.1in the root, EF Core and EF Core NodaTime changelogs. It goes there because a silent fix onmaingoes under Breaking before 11.0.0.Tests
NullOperandTranslationTests.ANullableElement_IsCheckedForNullpins the SQL for a nullable element (positive, negated, and on a nullableRangeSet) and for a required one, which is unchanged. With the fix stripped, it fails withactual: "r.\"Period\" @> r.\"Day\"".candidate fixedentries and nothing else, and pass once the entries are removed. The whole integration project passes (300 tests), and so does InfinityDisabled.range-predicate-over-a-null-column-is-nullstill 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