Skip to content

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

Closed

Description

@CaffeinatedCoder

Found by a pre-release sweep of main @ 934ec55; reproduced in a scratch test. The check is new in the unreleased 5.5.0 (changelog: "a filter … that compares a date or time ToJson() member with a column fails at migrations add").

Problem

ThrowIfFallbackComparedWithColumn (CustomMigrationsModelDiffer.cs:846) runs inside ResolveFilter (:822), which builds descriptors for both sides (ExtractAllIndexDescriptors(source), :148). For exclusion constraints it is reached through ResolveExclusionFilter (NpgsqlComplexIndexMigrationsModelDiffer.cs:1084) from BuildExclusionDescriptors(source) (:841). This breaks the rule that validation runs on the target model only: a snapshot that holds the refused filter can no longer be diffed, which includes the migration that removes the filter.

Scenario: 5.4.x scaffolded "ValidFrom" >= ({Profile.At}) (index) or {Profile.At} <> "ValidFrom" (exclusion), with Profile mapped ToJson() and At a DateTime. After upgrading to 5.5.0 the user removes the declaration, and migrations add throws "compares the JSON member 'Profile.At' with a column" instead of emitting the drop. has-pending-model-changes and Migrate()'s pending-changes check go through the same path (HasDifferences → GetDifferences). The index case needs a snapshot at rendering version ≥ 2; the exclusion case fires at any version.

Change

Record the fallback comparison while resolving, and throw only for target descriptors, next to ValidateQueryUsableLeadingParts.

Tests

NpgsqlDiff(snapshotWithFilter, modelWithoutIt) emits DropIndexOperation ix_at, and for the exclusion case the DROP CONSTRAINT IF EXISTS "ex_at" SQL. Both throw on HEAD. The existing target-side refusal tests stay green.

Activity

  1. added this to the 5.5.0 milestone on Oct 20, 2026
  2. added
    bug
    severity/high
    package/core
    package/postgresql
    area/expression-indexes
    area/constraints
    area/migrations
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/constraintsarea/expression-indexesarea/migrationsbugpackage/corepackage/postgresqlseverity/high

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions