Skip to content

Refuse a JSON date-vs-column filter on the target model only - #146

Merged
CaffeinatedCoder merged 1 commit into
mainfrom
fix/144-filter-check-target-only
Oct 20, 2026
Merged

CaffeinatedCoder merged 1 commit into
mainfrom
fix/144-filter-check-target-only

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #144

Problem

The check new in the unreleased 5.5.0 that refuses a filter comparing a date or time ToJson() member with a column ran inside ResolveFilter, which builds descriptors for both diff sides (and, for exclusion constraints, BuildExclusionDescriptors(source)). A snapshot holding such a filter, scaffolded by 5.4.x, could therefore never be diffed: removing the declaration made migrations add throw "compares the JSON member 'Profile.At' with a column" instead of emitting the drop, and has-pending-model-changes and Migrate()'s pending-changes check failed the same way. That breaks the rule that validation runs on the target model only.

Change

  • CustomMigrationsModelDiffer: the internal ResolveFilter overload returns the refusal through out string? refusal instead of throwing (ThrowIfFallbackComparedWithColumn → FallbackComparedWithColumn, message unchanged). IndexDescriptor carries it as FilterRefusal, outside equality, and the new ValidateFilterComparisons(targetIndexes) throws it next to ValidateQueryUsableLeadingParts. The protected ResolveFilter keeps throwing, so a subclass calling it sees no change.
  • NpgsqlComplexIndexMigrationsModelDiffer: ExclusionDescriptor carries FilterRefusal the same way, and ApplyExclusionConstraints throws it for target constraints only, beside ValidateUniqueExclusionNames.
  • CLAUDE.md: the sentence on this check now says it applies to the target model only.

No changelog change: the 5.5.0 line ("fails at migrations add") is still accurate, and the check has not shipped.

Tests

Two new tests in NpgsqlJsonDateFilterTests: NpgsqlDiff(snapshotWithFilter, modelWithout) emits DropIndexOperation ix_at (index filter, snapshot pinned at rendering version 2), and the DROP CONSTRAINT IF EXISTS "ex_at" SQL (exclusion filter). With the source files reverted to main, both fail with the refusal's InvalidOperationException (2 failed, 4 passed in the class). The existing target-side refusal tests stay green, and so does the unit suite (TestCategory!=Integration&TestCategory!=SqlServer): 571 passed.

🤖 Generated with Claude Code

ResolveFilter threw while building descriptors for both diff sides, so a
snapshot holding such a filter could not be diffed, not even by the
migration removing it. It now returns the refusal; the index and
exclusion descriptors carry it outside equality, and the differs throw
it for target descriptors only.

Closes #144

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 severity/high Wrong results, crash or failed writes in a realistic scenario package/core Affects EFCore.ComplexIndexes package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL area/expression-indexes Expression, typed LINQ and JSON member indexes area/constraints Temporal (WITHOUT OVERLAPS, PERIOD) and exclusion constraints area/migrations The differs, snapshot format, EnsureCreated and design-time wiring labels Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit a2332ae into main Oct 20, 2026
@CaffeinatedCoder
CaffeinatedCoder deleted the fix/144-filter-check-target-only branch October 20, 2026 11:22
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/expression-indexes Expression, typed LINQ and JSON member indexes area/migrations The differs, snapshot format, EnsureCreated and design-time wiring bug Something isn't working package/core Affects EFCore.ComplexIndexes package/postgresql Affects EFCore.ComplexIndexes.PostgreSQL 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.

The JSON date-vs-column filter check also runs on the source model, so a snapshot holding the filter cannot be diffed

1 participant