Repository navigation
fix: type the NULLs EF Core 10.0.2+ writes for an empty captured list of ranges or sets - #306
Merged
CaffeinatedCoder merged 2 commits intoOct 19, 2026
Conversation
… of ranges or sets EF Core 10.0.2 and later (dotnet/efcore#37216, backported as dotnet/efcore#37248) replace an empty VALUES parameter themselves, in SqlNullabilityProcessor, with (SELECT NULL AS "Value" WHERE FALSE) AS w, before the plugin's parameter-based pass. EmptyCollectionRewriter saw no empty VALUES and did nothing, the NULL went out bare, PostgreSQL typed it as text, and every Any or Count over an empty captured list of ranges or value sets failed on the server with 42883 ("operator does not exist: text && int4range", text && date[], text -|- daterange, isempty(text), ...), for every range and set type and every collection form. Npgsql EF 10.0.1-10.0.3 require EF Core >= 10.0.4, so most consumers of 10.0.0 see it; CI pins the 10.0.0 floor and did not (#297). The rewriter now handles both shapes: a SELECT holding an empty VALUES keeps the 10.0.0 rewrite (one row of typed NULLs under WHERE FALSE), for EF Core 10.0.0 and 10.0.1 and for any patch with Microsoft.EntityFrameworkCore.Issue37216 set; EF Core's table-less SELECT of null constants under WHERE FALSE gets each constant whose type is a registered range or set type cast to its store type (NULL::int4range), the mapping EF Core attached from the parameter's element mapping. Other types keep EF Core's SQL (EmptyCollectionGuardTests). The cast path is the one PR #292 wrote for #290, the same defect on the 11 line; that version dropped the VALUES path because EF Core 11 never produces it, which 10.x must keep. #292 is one commit holding the whole .NET 11 retarget, so this is a hand-extracted commit naming it rather than a cherry-pick -x. The four translation tests pin one SQL per shape through EmptyCollectionSql, which reads the EF Core Relational version the test host resolved and honours the off switch, so the floor leg and the newest-patch leg of #297 each assert theirs. The integration tests of the answers are unchanged. Measured with the test hosts floated to EF Core 10.0.13 / Npgsql EF 10.0.3 and src/ on the 10.0.0 floor: before, 4 of 289 translation and 5 of 280 integration tests failed; after, all pass on the floor and on the float. With the rewriter reverted to the 10.0.0 version and the tests kept, the same 4 and 5 fail on the float and the floor stays green. The changelog line names the stopgap AppContext.SetSwitch("Microsoft.EntityFrameworkCore.Issue37216", true) and its cost: EF Core's own fix for empty parameter collections of other types is lost. Issue #302, fixed on release/10.x only; closed by hand after the merge, since a closing keyword acts only on main. Found-By: OT Defect-Class: SQL Co-Authored-By: Claude Fable 5.1 <[email protected]>
CaffeinatedCoder
enabled auto-merge
October 19, 2026 11:22
This was referenced Oct 19, 2026
fix: implement IFormattable on every value set so Native AOT with the .NET 11 SDK does not trap
#309
Merged
CaffeinatedCoder
added a commit
that referenced
this pull request
Oct 19, 2026
… well as the floor The EF test projects only ever ran on the floor the packages ship against (Npgsql EF 10.0.0, which resolves EF Core 10.0.0), while a consumer's application resolves the newest patch: Npgsql EF 10.0.1-10.0.3 require EF Core >= 10.0.4. #302 came in through that gap, green on every floor run and failing on the server on every patch from EF Core 10.0.2 on. test/Directory.Build.targets floats the EF test projects (every project whose name contains EFCore) when -p:EfFloat and -p:NpgsqlEfFloat are passed: it adds EF Core, Relational, Npgsql EF and Npgsql EF NodaTime at those versions and updates Design to match. Direct references win, so the test hosts load the newer assemblies while src/ still compiles against the floor, which is a consumer's situation. Without the properties nothing changes. There is no root Directory.Build.targets to shadow, the consumer smoke test builds outside the repository, and the conventions suite passes unchanged (403/403). dotnet.yml's integration-legs matrix gains an ef axis, floor and newest-patch, and the newest published versions (EF Core 10.0.13, Npgsql EF 10.0.3) sit in one matrix include, so a new patch is a one-line bump. The newest-patch legs run all four EF projects on PostgreSQL 16 and 18, reusing the legs' container setup, and first check that every EF test host's deps.json names the versions asked for, so a float that stops reaching the hosts fails instead of testing the floor twice. The test loop runs every project before failing, as the step's shell stops at the first failing command and the glob puts the translation projects after the integration ones; a first CI run with the fix reverted stopped after the integration project and never showed the four translation failures. The "Integration (live PostgreSQL)" gate needs every leg, so the new legs are required with no ruleset change, and the floor legs stay required as they were. No scheduled run against EF Core's servicing builds: the dnceng dotnet10 feed holds only 10.0.0 prereleases (newest 10.0.0-rtm.25513.102), and GitHub fires schedule only from the default branch. #297 records what was tried. Proof, locally on release/10.x with the #302 fix (EmptyCollectionRewriter.cs from PR #306) reverted to d883b12^: - float (10.0.13 / 10.0.3): translation 291/295 (the four empty-captured-list tests), integration 275/280 (#302's five, 42883: operator does not exist: text && text[]), NodaTime translation 91/91, InfinityDisabled 4/4 - floor: 295/295, 280/280, 91/91, 4/4 With the fix in place, the CI steps replayed under bash pass on the float: 295, 280, 91, 4. Issue #297, on release/10.x only; closed by hand after the merge, since a closing keyword acts only on main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #302
Stacked on #305 (
chore/304-open-10.1.0), which opens## [10.1.0]; retarget torelease/10.xonce it merges. #302 is fixed only onrelease/10.x(mainhas the 11-line twin #290 in #292), soCloseswill not act: close it by hand after the merge, with a link here.Problem
EmptyCollectionRewriter(#137, 10.0.0) handles the shape EF Core 10.0.0 and 10.0.1 give an empty captured collection of ranges or value sets sent one parameter per element: aVALUESwith no rows, which it replaces with one row of typedNULLs underWHERE FALSE. EF Core 10.0.2 and later (dotnet/efcore#37216, backported as dotnet/efcore#37248) replace the emptyVALUESthemselves, inSqlNullabilityProcessor, with(SELECT NULL AS "Value" WHERE FALSE) AS w. That runs before the plugin's pass, so the rewriter saw no emptyVALUESand did nothing, and theNULLwent out bare. PostgreSQL types a bareNULLastext, and everyAny/Countover an empty list failed on the server with42883: operator does not exist: text && int4range(ortext && date[],text -|- daterange,function isempty(text) does not exist, …), for every range and set type and every collection form.Live for most consumers: Npgsql EF 10.0.1–10.0.3 require EF Core ≥ 10.0.4. Only an application pinned to Npgsql EF 10.0.0 with EF Core 10.0.0 or 10.0.1 — this repository's CI (#297) — does not see it. In memory the same
AnyisfalseandCountis0, and docs/efcore.md promises "an empty list matches nothing".Change
src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/EmptyCollectionRewriter.cs: handles both shapes. ASELECTholding an emptyVALUESkeeps the 10.0.0 rewrite (one row of typedNULLs underWHERE FALSE), for the floor and for any patch withMicrosoft.EntityFrameworkCore.Issue37216set. A table-lessSELECTof null constants underWHERE FALSE— EF Core's replacement — gets each constant whose type is a registered range or set type cast to its store type (NULL::int4range), the mapping EF Core attached from the parameter's element mapping. Other types keep EF Core's SQL (EmptyCollectionGuardTests). The cast path is the one PR build: retarget main to .NET 11 for 11.0.0-preview.1 #292 wrote for EF Core 11 reads an empty captured collection as a bare NULL that PostgreSQL types astext:operator does not exist: text && int4range#290 onmain; that version dropped theVALUESpath because EF Core 11 never produces it, which 10.x must keep. build: retarget main to .NET 11 for 11.0.0-preview.1 #292 is one commit holding the whole .NET 11 retarget, so this is a hand-extracted commit naming it, not acherry-pick -x.ValueRangesParameterBasedSqlProcessorFactory.cs: the comment names both shapes.test/CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests/EmptyCollectionSql.cs(new): picks the SQL shape by the EF Core Relational version the test host resolved (informational version, since the assembly version stays10.0.0.0), honouring the off switch. The four translation tests pin one SQL per shape through it, so the floor leg and the newest-patch leg of 10.x CI: run the EF Core suites on the newest EF Core / Npgsql 10 patch and the daily servicing builds, not only the floor #297 each assert theirs.CHANGELOG.md,src/CodoMetis.ValueRanges.EFCore.PostgreSQL/CHANGELOG.md: the line under## [10.1.0], naming the stopgapAppContext.SetSwitch("Microsoft.EntityFrameworkCore.Issue37216", true)and its cost (EF Core's own fix for empty parameter collections of other types is lost).src/CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime/CHANGELOG.md: notes the NodaTime ranges and sets get the fix through the base package.No docs change: the promise in
docs/efcore.md("an empty list matches nothing") is what the fix restores, andclaims.jsonquotes it.Tests
The test hosts were floated to EF Core 10.0.13 / Npgsql EF 10.0.3 with a scratch
test/Directory.Build.targets(not committed;-p:EfFloat=10.0.13 -p:NpgsqlEfFloat=10.0.3), whilesrc/stays compiled against the 10.0.0 floor, as a consumer's application is.Reproduced before the change, on the float:
CodoMetis.ValueRanges.EFCore.PostgreSQL.Tests4 of 289 failed (Any_OverAnEmptyCapturedList_ReadsNoRows,Count_OverAnEmptyCapturedList_ReadsNoRows,AnyAlone_OverAnEmptyCapturedList_ReadsNoRows,AnyBesideContains_OverAnEmptyCapturedList_ReadsNoRows);…IntegrationTests(PostgreSQL 16, Docker) 5 of 280 failed (AnEmptyCollection_AnyAndCountAnswerAsInMemory,AnEmptyCollectionAlone_…,AnEmptyCollectionBesideContains_…,CapturedCollectionProbeTests.Ranges_AnswerAsInMemory,ValueSets_AnswerAsInMemory) with42883on every range and set type.With the change:
Revert proof (
verify-the-guard): withEmptyCollectionRewriter.csput back to therelease/10.xversion and the updated tests kept:The translation failures are the asserted SQL: expected
SELECT NULL::int4range AS "Value", gotSELECT NULL AS "Value". The integration failures are the server's42883(text && daterange×12,text && date[]×12,isempty(text)×7,cardinality(text)×7,text <@ date[]×6,text -|- daterange×6,text && int4range×2,text && text[]×1). The floor stays green with the fix reverted because the 10.0.0 path is unchanged.🤖 Generated with Claude Code