Skip to content

fix: Any and Count over a captured list of ranges read the list from VALUES - #172

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

CaffeinatedCoder merged 4 commits into
mainfrom
fix/captured-range-collection-any-count

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #76

Stacked on #170 (fix/empty-captured-collection) → #169 → #168 → #167: merge those first, then retarget this to main. #170 goes first because this change would otherwise turn an empty range list from a correct answer into EF Core's "Empty collections are not supported as inline query roots".

Problem

Any, Count and other LINQ over a captured list of ranges that no Contains read went to PostgreSQL as one parameter. Npgsql typed it as a multirange, so the query read it through unnest of a multirange, which merges overlapping and adjacent ranges and drops empty ones: wanted.Count(w => w.Overlaps(r.Seats)) over [1,5] and [3,8] was 1 where memory says 2, withEmpty.Any(w => w.IsEmpty()) was false, all without an error. CapturedCollectionProbeTests measured it wider: every range type and collection form; Any(w => w == c) failing loudly with 42809; and every Any/Count over a TimeRange list throwing InvalidCastException. 9.1.0 had fixed only the Contains case (#71) because the rest changed an answer, which by the release rule waits for the major.

Change

  • src/CodoMetis.ValueRanges.EFCore.PostgreSQL/Query/ValueRangesQueryExpressionInterceptor.cs: every captured range collection is switched to ParameterTranslationMode.MultipleParameters, as a value set collection already was; the ContainsSourceCollector and its limit are gone. Any and Count read the list from VALUES (@p1), (@p2), …, one typed parameter per range, so the list is the list. EF.Parameter(wanted) is refused for every use of a range collection, as it is for sets, with the message saying why and what to write. An empty list reads no rows through fix: Any and Count over an empty captured collection read no rows instead of throwing #170.
  • test/oracles/seeds/set-collection-sent-as-one-parameter.patch: refreshed against the new interceptor (the defect it plants is unchanged: value set collections not switched); dotnet run tools/oracles.cs seeds set-collection-sent proves it is still caught.
  • test/oracles/candidates.json: the Any/Count over a captured list of ranges silently merge overlapping ranges and drop empty ones #76 row removed. claims.json: E38 restated as the parity it now is (E38-captured-range-collection-any-count), quoting the new guide sentence, held by RangeCollectionContainsTests, RangeCollectionTranslationTests and CapturedCollectionProbeTests.
  • docs/efcore.md (list of ranges): Any/Count read from VALUES, an empty list matches nothing, the EF.Constant workaround is retired, EF.Parameter throws everywhere. CHANGELOG.md, src/CodoMetis.ValueRanges.EFCore.PostgreSQL/CHANGELOG.md: the Breaking row; docs/migration.md: Check Any and Count over a captured list of ranges.

Tests

  • RangeCollectionTranslationTests: AnyAlone_OverACapturedList_ReadsTheRangesFromValues, CountAlone_…, AnyAlone_OverAnEmptyCapturedList_ReadsNoRows, AnyAlone_OverEFParameter_IsRefusedWithWhatToWriteInstead.
  • RangeCollectionContainsTests (PostgreSQL): AnyAndCountAloneOverTheCollection_AnswerAsInMemory over overlapping, adjacent, duplicate and with-an-empty-range lists through Count(Overlaps), Count(==), Any(==), Any(IsEmpty) and Count(IsAdjacentTo); AnEmptyCollectionAlone_AnyAndCountAnswerAsInMemory; AnyAloneOverTheCustomTimeRange_AnswersAsInMemory; AnyAloneOverEFParameter_IsRefusedWithWhatToWriteInstead.
  • CapturedCollectionProbeTests.Ranges_AnswerAsInMemory passes with its Any/Count over a captured list of ranges silently merge overlapping ranges and drop empty ones #76 candidate gone: every form × list × operation of all eleven range types agrees with memory.
  • With the interceptor change reverted: the four translation tests, the three executed tests and the probe (1,710 lines, e.g. DateRange over adjacent as Array, alone: Count(Overlaps) for (,) → memory=2, database=1) fail.
  • The whole suite, both integration projects in Docker included, is green.

🤖 Generated with Claude Code

CaffeinatedCoder and others added 2 commits October 18, 2026 15:50
…VALUES

Any, Count and other LINQ over a captured list of ranges that no Contains
read went to PostgreSQL as one parameter, which Npgsql typed as a multirange.
unnest of a multirange merges overlapping and adjacent ranges and drops empty
ones, so Count(w => w.Overlaps(r.Seats)) over [1,5] and [3,8] was 1 where
memory says 2, and withEmpty.Any(w => w.IsEmpty()) was false, without an
error. Any(w => w == c) failed loudly with 42809 and every Any or Count over
a TimeRange list threw InvalidCastException. 9.1.0 fixed only the Contains
case (#71), because the rest changed an answer and waited for the major.

Every captured range collection is now sent one parameter per range, as a
value set collection already is, so Any and Count read the list from VALUES
and the list is the list; EF.Parameter(wanted) is refused for every use of a
range collection, with the message saying why. An empty list reads no rows
through the EmptyCollectionRewriter, which is why that fix precedes this one.
The set-collection seed is refreshed against the new interceptor and still
caught; claim E38 is restated as the parity it now is; the #76 candidate is
removed.

With the interceptor change reverted, four translation tests, three executed
tests and CapturedCollectionProbeTests (1,710 lines) fail for the defect.

Closes #76

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 silent Answers wrongly without throwing — fixes go in the next major, never deferred breaking Changes an answer or a signature — needs a major found-by/oracle Found by the generated-oracle machinery (claims × API surfaces) area/ranges Range unions, variants and the shape engines package/efcore Affects CodoMetis.ValueRanges.EFCore.PostgreSQL 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 18, 2026
…collection-any-count

# Conflicts:
#	CHANGELOG.md
#	docs/migration.md
#	test/oracles/candidates.json
Base automatically changed from fix/empty-captured-collection to main October 18, 2026 14:25
@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 3ab580b into main Oct 18, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/captured-range-collection-any-count branch October 18, 2026 14:29
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 breaking Changes an answer or a signature — needs a major 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/high Wrong results, crash or failed writes in a realistic scenario silent Answers wrongly without throwing — fixes go in the next major, never deferred

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any/Count over a captured list of ranges silently merge overlapping ranges and drop empty ones

1 participant