Repository navigation
fix: cast non-string JSON members in exclusion constraint filters (#78) - #108
Merged
Merged
Conversation
Exclusion constraint filters resolve JSON placeholders under rendering 1,
so that the 5.4.0 rendering change never rebuilt a constraint. Rendering 1
reads every member as text, so a typed filter on an int or bool ToJson()
member scaffolded SQL PostgreSQL rejects: ("doc" ->> 'Rank') > 5 fails with
42883, and a bare ("doc" ->> 'Active') with 42804.
A member the current rendering casts (number, boolean, uuid, enum) now
takes that rendering in exclusion filters too, on both sides of the diff.
As text it never applied in a comparison; where it did apply (IS NOT NULL,
a string literal), the cast keeps NULL as NULL and the same rows, and no
migration is produced since both sides resolve alike. Strings, primitive
collections, json, bytea and the date/time text fallbacks keep rendering 1,
since -> and ->> differ on a JSON null.
Proven by seeding: without the switch the differ test fails and the
integration test fails with 42883 on PostgreSQL 18; widening it to every
member fails the string and primitive-collection assertions.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # CHANGELOG.md # src/EFCore.ComplexIndexes.PostgreSQL/CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #78
Problem
A typed exclusion constraint filter on a non-string
ToJson()member scaffolded SQL that PostgreSQL rejects when the migration is applied:BuildExclusionDescriptorsresolves exclusion filters withrenderingVersion: 1, which reads every JSON member as text, so that existing constraints never rebuild. The index path renders the same predicate asCAST("doc" ->> 'Rank' AS integer) > 5, which applies.Change
NpgsqlComplexIndexMigrationsModelDiffer: exclusion filters resolve throughResolveExclusionFilter, which flags the resolution. InResolveUnmappedPart, a leaf that the current rendering casts (RendersAsCast: a number, boolean, uuid or enum, not a string, primitive collection,json/jsonb,byteaor date/time text fallback) takes the current rendering under that flag.->(jsonb) under the current rules where rendering 1 had->>(text), and the two treat a JSON null differently, so{Doc.Tags} IS NOT NULLwould change meaning. A cast keeps NULL as NULL. For a cast member, a filter that did apply under rendering 1 (IS NOT NULL, or a comparison with a string literal) therefore holds for the same rows. Both sides of the diff resolve alike, so no existing constraint gets a migration.ResolveFilterstays untouched (stream C's file). The flag is a field set for the duration of the call.### Fixedline goes into the root and PostgreSQL changelogs.Tests
NpgsqlJsonMemberRenderingTests.Exclusion_filters_cast_non_string_members:Rank > 5, nestedAddress.Zip > 0andHasFilter(x => x.Profile.Active)renderCAST(… AS integer)/#>> '{Address,Zip}'/CAST(… AS boolean).{Profile.Tags} IS NOT NULLkeeps->>.Rollout_does_not_touch_exclusion_constraintsnow covers the new constraints too: a pre-5.4.0 snapshot against the current model produces no exclusion operations.PostgresIntegrationTests.Exclusion_filter_on_non_string_json_members_applies: both constraints apply on PostgreSQL 18 without runtime wiring, and each rejects an overlapping row in its own partition.42883: operator does not exist: text > integer. With the switch widened to every member, the string-member (City) and primitive-collection (Tags) assertions fail.🤖 Generated with Claude Code