Skip to content

fix: Any and Count over an empty captured collection read no rows instead of throwing - #170

Merged
CaffeinatedCoder merged 4 commits into
mainfrom
fix/empty-captured-collection
Oct 18, 2026
Merged

CaffeinatedCoder merged 4 commits into
mainfrom
fix/empty-captured-collection

Conversation

@CaffeinatedCoder

@CaffeinatedCoder CaffeinatedCoder commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Closes #137

Stacked on #169 (fix/date-extremes-adjacency-divergence) → #168 → #167: merge those first, then retarget this to main. It is placed before the #76 fix on purpose: #76 switches every captured range collection to one parameter per range, which would have turned an empty range list from a correct answer into this exception, so the empty case has to read no rows first.

Problem

Any or Count with a predicate over an empty captured collection threw InvalidOperationException: Empty collections are not supported as inline query roots at translation, for every value set type wherever the collection was used and for every range type beside a Contains. Memory returns false and 0. The plugin sends such a collection one parameter per element (ParameterTranslationMode.MultipleParameters), EF Core expands the parameter into VALUES rows in its parameter-based processing, and its SQL generator refuses to write a VALUES with no rows.

Change

  • src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/EmptyCollectionRewriter.cs (new): after the provider's parameter-based processing, a SELECT whose table list holds a VALUES with no rows gets one row of typed NULLs in its place and FALSE on its WHERE, so it reads no rows: EXISTS is false, count(*) is 0, All is true. The column types come from the columns that reference the VALUES alias in the same SELECT, so the row is (VALUES (NULL::int4range)) and every operator on it types; EF Core folds the predicate to WHERE FALSE. Only a VALUES whose referenced column is a registered range or value set type is rewritten; a collection of another type that a context in MultipleParameters mode sends the same way keeps EF Core's own behaviour. It works on the SQL tree, so it holds for every collection form and every LINQ shape that ends in a VALUES root, and EF Core has already disabled SQL caching when it read the collection, so a later execution with elements is generated afresh.
  • ValueRangesParameterBasedSqlProcessorFactory: runs the rewriter before ValueSetSqlGuard on the processor's result.
  • test/oracles/candidates.json: the Any/Count over an empty captured collection of value sets (or of ranges beside Contains) throws 'Empty collections are not supported as inline query roots' #137 row removed. docs/efcore.md (list of sets, Good to know): an empty list matches nothing. CHANGELOG.md, src/CodoMetis.ValueRanges.EFCore.PostgreSQL/CHANGELOG.md: the 10.0.0 Fixed row.

Tests

  • SetCollectionTranslationTests.Any_OverAnEmptyCapturedList_ReadsNoRows and Count_OverAnEmptyCapturedList_ReadsNoRows, RangeCollectionTranslationTests.AnyBesideContains_OverAnEmptyCapturedList_ReadsNoRows: the SQL, … FROM (VALUES (NULL::text[])) AS w("Value") WHERE FALSE.
  • SetCollectionContainsTests.AnEmptyCollection_AnyAndCountAnswerAsInMemory (also All) and RangeCollectionContainsTests.AnEmptyCollectionBesideContains_AnyAndCountAnswerAsInMemory, executed against PostgreSQL.
  • CapturedCollectionProbeTests passes with the Any/Count over an empty captured collection of value sets (or of ranges beside Contains) throws 'Empty collections are not supported as inline query roots' #137 candidate gone, so every empty-list row of every discovered type and collection form now agrees with memory.
  • With the rewriter call removed: the three translation tests and the two executed tests fail with Empty collections are not supported as inline query roots, and the probe reports 176 such lines.
  • The whole suite, both integration projects in Docker included, is green.

🤖 Generated with Claude Code

…tead of throwing

Any or Count with a predicate over an empty captured collection of value
sets — or of ranges beside a Contains — threw InvalidOperationException
("Empty collections are not supported as inline query roots") at translation,
where memory answers false and 0. The plugin sends such a collection one
parameter per element, EF Core expands that parameter into VALUES rows in its
parameter-based processing, and its SQL generator refuses a VALUES with none.

EmptyCollectionRewriter runs after the provider's processing, from the
decorated parameter-based processor factory: a SELECT whose table list holds a
VALUES with no rows gets one row of typed NULLs in its place and FALSE on its
WHERE, so it reads no rows — EXISTS is false, count(*) is 0, All is true. The
column types come from the columns referencing the VALUES alias in the same
SELECT, so the row is (VALUES (NULL::int4range)) and every operator on it
types. EF Core has already disabled SQL caching when it read the collection,
so a later execution with elements is generated afresh. Placed before the #76
fix on purpose: switching every range collection to one parameter per range
would otherwise turn an empty range list from a correct answer into this
exception.

With the rewriter call removed, the three new translation tests and the two
new executed tests fail with EF Core's message and CapturedCollectionProbeTests
reports 176 such lines; its #137 candidate is removed.

Closes #137

Found-By: OT
Defect-Class: SQL

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 10.0.0 milestone Oct 18, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/ranges Range unions, variants and the shape engines area/value-sets Value set families and wrapper arities package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference stacked Base is another open PR; merge in order, CI does not run until it targets main labels Oct 18, 2026
…column

A collection of some other type that a context configured for
MultipleParameters sends the same way keeps EF Core's own behaviour: the
plugin did not put it on this path, so it does not change what it answers.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…captured-collection

# Conflicts:
#	test/oracles/candidates.json
Base automatically changed from fix/date-extremes-adjacency-divergence to main October 18, 2026 14:21
@CaffeinatedCoder CaffeinatedCoder removed the stacked Base is another open PR; merge in order, CI does not run until it targets main label Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit ee18e3b into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/empty-captured-collection branch October 18, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/ranges Range unions, variants and the shape engines area/value-sets Value set families and wrapper arities bug Something isn't working found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL severity/low Cosmetic, message or documentation-level difference

Projects

None yet

1 participant