fix: PK/FK constraints with an expression (e.g. RELY) dropped and re-added on every incremental run - #1552
Merged
sd-db merged 1 commit intoJun 22, 2026
Conversation
sd-db
force-pushed
the
sd-db/triage/dbt-1513-rely-constraint-churn
branch
from
June 20, 2026 08:52
b8b9bea to
18817e1
Compare
Collaborator
Author
|
/integration-test |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
|
Integration tests dispatched for PR #1552 by @sd-db. Track progress in the Actions tab. |
|
Integration results for PR #1552 — UC cluster ✅ success · SQL warehouse ✅ success · All-purpose cluster ✅ success · Shard coverage ✅ success |
jprakash-db
approved these changes
Jun 22, 2026
…LY expression A primary/foreign key declared with an `expression` such as RELY was dropped (DROP CONSTRAINT ... CASCADE) and re-added on every incremental run: RELY/NORELY is not exposed by information_schema, so the catalog-read constraint never matched the model's. The CASCADE silently dropped dependent foreign keys and could fail with INTERNAL_ERROR on newer Unity Catalog. Constraint reconciliation now compares PK/FK on (name, columns), ignoring the un-round-trippable expression (and the expression-form FK's to/to_columns) while still detecting genuine FK target changes. Closes databricks#1513
sd-db
force-pushed
the
sd-db/triage/dbt-1513-rely-constraint-churn
branch
from
June 22, 2026 04:59
6ffff20 to
999704d
Compare
This was referenced Jun 22, 2026
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.
Description
Resolves #1513.
A contract-enforced incremental PK/FK declaring an
expressionwas dropped and re-added on every run. The catalog read-back (information_schema) never carries theexpression— noRELY/NORELY, and expression-form FKs come back asto/to_columns— so it never matched the model, andget_diffflagged the constraint as both add and drop every run (for anyexpression, not justRELY). The PK drop isDROP CONSTRAINT ... CASCADE, which silently drops dependent FKs and canINTERNAL_ERRORon newer UC.Fix
Compare PK/FK on
(type, name, columns)(dropping the un-round-trippableexpression, andto/to_columnsfor FKs), but emit the original constraints so an ADD keeps itsRELY. Explicit FK target changes (to/to_columns) are still reconciled.Behavior change (accepted regression)
Changing the
expressionon an existing PK/FK —RELY↔NORELY, or an expression-form FK's target — is no longer applied on incremental runs; use--full-refresh. It only worked before as a side effect of the every-run recreate, and the catalog can't report the current state without fragileSHOW CREATE TABLEparsing. PK/FK are informational (NOT_ENFORCED), so this is metadata-only.Tests
TestConstraintsConfig): RELY PK no-op, expression-form FK no-op, explicit FK repoint reconciled, new RELY PK keeps its expression.TestIncrementalRelyConstraintReconciliation): a dependent FK survives an incremental re-run of a RELY-PK parent (asserted viainformation_schema); fails onmain, passes here.Checklist
CHANGELOG.mdupdated.