Skip to content

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 into
release/10.xfrom
fix/302-empty-collection-ef-core-patches
Oct 19, 2026
Merged

CaffeinatedCoder merged 2 commits into
release/10.xfrom
fix/302-empty-collection-ef-core-patches

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #302

Stacked on #305 (chore/304-open-10.1.0), which opens ## [10.1.0]; retarget to release/10.x once it merges. #302 is fixed only on release/10.x (main has the 11-line twin #290 in #292), so Closes will 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: a VALUES with no rows, which it replaces with one row of typed NULLs under WHERE FALSE. EF Core 10.0.2 and later (dotnet/efcore#37216, backported as dotnet/efcore#37248) replace the empty VALUES themselves, in SqlNullabilityProcessor, with (SELECT NULL AS "Value" WHERE FALSE) AS w. That runs before the plugin's pass, so the rewriter saw no empty VALUES and did nothing, and the NULL went out bare. PostgreSQL types a bare NULL as text, and every Any/Count over an empty list failed on the server with 42883: operator does not exist: text && int4range (or text && 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 Any is false and Count is 0, and docs/efcore.md promises "an empty list matches nothing".

Change

  • src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/EmptyCollectionRewriter.cs: handles both shapes. A SELECT holding an empty VALUES keeps the 10.0.0 rewrite (one row of typed NULLs under WHERE FALSE), for the floor and for any patch with Microsoft.EntityFrameworkCore.Issue37216 set. A table-less SELECT of null constants under WHERE 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 as text: operator does not exist: text && int4range #290 on main; that version dropped the VALUES path 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 a cherry-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 stays 10.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 stopgap AppContext.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, and claims.json quotes 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), while src/ 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.Tests 4 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) with 42883 on every range and set type.

With the change:

Suite Floor (EF Core 10.0.0 / Npgsql EF 10.0.0) Float (EF Core 10.0.13 / Npgsql EF 10.0.3)
EFCore.PostgreSQL.Tests 289 / 289 289 / 289
EFCore.PostgreSQL.IntegrationTests 280 / 280 280 / 280
EFCore.PostgreSQL.NodaTime.Tests (CI) 83 / 83
Conventions.Tests all green —

Revert proof (verify-the-guard): with EmptyCollectionRewriter.cs put back to the release/10.x version and the updated tests kept:

### REVERTED translation float
  Failed Any_OverAnEmptyCapturedList_ReadsNoRows [11 ms]
  Failed AnyAlone_OverAnEmptyCapturedList_ReadsNoRows [23 ms]
  Failed AnyBesideContains_OverAnEmptyCapturedList_ReadsNoRows [20 ms]
  Failed Count_OverAnEmptyCapturedList_ReadsNoRows [10 ms]
Failed!  - Failed:     4, Passed:   285, Skipped:     0, Total:   289
### REVERTED translation floor
Passed!  - Failed:     0, Passed:   289, Skipped:     0, Total:   289
### REVERTED integration float
  Failed AnEmptyCollectionBesideContains_AnyAndCountAnswerAsInMemory [74 ms]
  Failed AnEmptyCollectionAlone_AnyAndCountAnswerAsInMemory [47 ms]
  Failed AnEmptyCollection_AnyAndCountAnswerAsInMemory [27 ms]
  Failed Ranges_AnswerAsInMemory [6 s]
  Failed ValueSets_AnswerAsInMemory [9 s]
Failed!  - Failed:     5, Passed:   275, Skipped:     0, Total:   280
### source restored
### RESTORED translation float
Passed!  - Failed:     0, Passed:   289, Skipped:     0, Total:   289

The translation failures are the asserted SQL: expected SELECT NULL::int4range AS "Value", got SELECT NULL AS "Value". The integration failures are the server's 42883 (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

… 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 CaffeinatedCoder added this to the 10.1.0 milestone Oct 19, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working area/range-set RangeSet and multirange algebra area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime severity/high Wrong results, crash or failed writes in a realistic scenario stacked Base is another open PR; merge in order, CI does not run until it targets main labels Oct 19, 2026
Base automatically changed from chore/304-open-10.1.0 to release/10.x October 19, 2026 11:21
@CaffeinatedCoder CaffeinatedCoder removed the stacked Base is another open PR; merge in order, CI does not run until it targets main label Oct 19, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit 05e5364 into release/10.x Oct 19, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/302-empty-collection-ef-core-patches branch October 19, 2026 11:26
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]>
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/value-sets Value set families and wrapper arities bug Something isn't working package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL package/efcore-nodatime Affects CodoMetis.ValueRanges.EFCore.PostgreSQL.NodaTime severity/high Wrong results, crash or failed writes in a realistic scenario

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant