Skip to content

fix(postgresql): refuse a filter comparing a JSON date member with a column - #128

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
fix/119-json-date-filter
Oct 20, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
fix/119-json-date-filter

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #119

Stacked on #126 (#118) → #124 (#117) → #123 (#94) → #122 (#80) → #121 (#101); merge those first.

Problem

Since 5.4.0 a DateTime, DateTimeOffset, DateOnly or TimeOnly member of a ToJson() document resolves to its text, because the cast EF Core's queries use is not IMMUTABLE and cannot appear in an index. In a filter, the text met a typed column:

b.HasComplexIndex(x => x.Id, x => x.Profile.At < x.ValidFrom, indexName: "ix_at");

scaffolded WHERE ("profile" ->> 'At') < "ValidFrom", and PostgreSQL refused the migration at apply: operator does not exist: text < timestamp with time zone (reproduced on PostgreSQL 18). Exclusion constraint filters, which stay on rendering 1, failed the same way. The parity sweep (#101) found it: 24 rows.

Change

This is outside the typed translator. The typed translator cannot see that a path is a JSON member; only the differ can. Both edits are confined to filter resolution:

  • CustomMigrationsModelDiffer.ResolveFilter (core, stream C's file): records which placeholders resolved to a text fallback, and refuses one compared (=, <>, <, <=, >, >=) with a quoted column or another typed placeholder, on either side, naming the member and the alternatives. A null test, a comparison with a string literal and every other use resolve as before. ResolvePlaceholder returns the part's TextFallback.
  • NpgsqlComplexIndexMigrationsModelDiffer.ResolveUnmappedPart (stream B's file): under rendering 1, an exclusion filter's member that falls back to text under the current rendering is flagged the same way. Nothing else changes for rendering-1 parts.
  • waivers.txt: the 24 rows now fail at migrations add by design; their block says so.
  • Changelog ### Fixed line (root and PostgreSQL), docs/postgresql-indexes.md (JSON member indexes), CLAUDE.md (the TextFallback paragraph).

Not breaking: every refused filter failed at apply before.

Tests

  • New NpgsqlJsonDateFilterTests: a typed filter, a column-first string filter and an exclusion constraint filter that compare a JSON date member with a column are refused at migrations add; IS NOT NULL, a string literal and a typed JSON member compared with a column still resolve.
  • With both edits reverted, the three refusal tests fail; with only the Npgsql line reverted, the exclusion case fails.
  • Full suite 444/444 including the PostgreSQL integration suite.

🤖 Generated with Claude Code

…column (#119)

Since 5.4.0 a date or time member of a ToJson() document resolves to its
text, because the cast EF Core's queries use is not IMMUTABLE and cannot
appear in an index. In a filter that text met a typed column:
x => x.Profile.At < x.ValidFrom scaffolded
("profile" ->> 'At') < "ValidFrom", and PostgreSQL refused it at apply
with "operator does not exist: text < timestamp with time zone".
Exclusion constraint filters, pinned to rendering 1, failed the same way.

ResolveFilter now knows which placeholders resolved to such a text
fallback and refuses a comparison of one with a column or another typed
placeholder at migrations add, naming the member. A null test and a
comparison with a string literal still apply, as before. The Npgsql
differ flags those members under rendering 1 for exclusion filters too.

This touches the core differ and the Npgsql differ, outside the typed
translator: the edits are confined to filter resolution.

Verified with the change reverted: the three refusal tests fail (the
exclusion case also with only the Npgsql line reverted). The parity
sweep's 24 rows for it now fail at migrations add instead of rendering.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 5.5.0 milestone Oct 20, 2026
@CaffeinatedCoder CaffeinatedCoder added bug Something isn't working stacked Base is another open PR; merge in order, CI does not run until it targets main severity/low Cosmetic, message or documentation-level difference package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL area/indexes Complex-property, composite, unique and filtered indexes area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints labels Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder changed the base branch from fix/118-null-check-shapes to main October 20, 2026 07:14
@CaffeinatedCoder
CaffeinatedCoder merged commit 83acc3d into main Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/119-json-date-filter branch October 20, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints area/indexes Complex-property, composite, unique and filtered indexes bug Something isn't working package/postgresql Affects EFCore.ComplexIndexes.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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typed filters: a date or time JSON member compared with a column fails at apply (text against timestamp)

1 participant