Skip to content

fix: unnamed primary keys dropped and re-added on every incremental run#1554

Closed
sd-db wants to merge 2 commits into
mainfrom
fix/1333-unnamed-pk-constraint-churn
Closed

fix: unnamed primary keys dropped and re-added on every incremental run#1554
sd-db wants to merge 2 commits into
mainfrom
fix/1333-unnamed-pk-constraint-churn

Conversation

@sd-db

@sd-db sd-db commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

What

An unnamed primary key (type: primary_key with no name) is auto-named by Databricks. On incremental runs the model carries name=None while the catalog read carries the server-assigned name, so ConstraintsConfig.get_diff never matched them and issued DROP CONSTRAINT ... CASCADE + re-add every run — silently dropping dependent foreign keys (and erroring with TABLE_OR_VIEW_NOT_FOUND under concurrent DDL, per the report).

This is the same class of bug as #1552 (RELY expression), on a different non-round-trippable field: the name.

Fix

  • A primary key is now matched on its columns alone (a table has exactly one PK), so an unnamed PK adopts the catalog's server-assigned name instead of churning.
  • A deliberate rename of a named PK (same columns, different name) is still reconciled — handled in get_diff, not the comparison key.
  • dbt now warns when a foreign key is declared without a name, since unnamed FKs churn by the same mechanism. Not fixed here: FK columns aren't a unique key, so they can't be safely de-named — assigning a name avoids it.

Tests

Closes #1333.

@sd-db sd-db requested a review from jprakash-db as a code owner June 22, 2026 12:40
Databricks auto-names an unnamed PK, so the model's name=None never matched the catalog and reconciliation issued DROP CONSTRAINT ... CASCADE + re-add every incremental run, silently dropping dependent FKs. Match a PK on its columns alone; a named PK rename is still reconciled. Warn when a foreign key is declared without a name, since unnamed FKs churn the same way.
@sd-db sd-db force-pushed the fix/1333-unnamed-pk-constraint-churn branch from 8b48d09 to a65475b Compare June 22, 2026 12:41
@sd-db

sd-db commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator Author

/integration-test

@github-actions

Copy link
Copy Markdown

Integration tests dispatched for PR #1554 by @sd-db. Track progress in the Actions tab.

@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks/relation_configs
  constraints.py 78
Project Total  

This report was generated by python-coverage-comment-action

@github-actions

Copy link
Copy Markdown

Integration results for PR #1554 — UC cluster ✅ success · SQL warehouse ✅ success · All-purpose cluster ✅ success · Shard coverage ✅ success

Run details.

@sd-db

sd-db commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator Author

Closed in favour of #1561

@sd-db sd-db closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TABLE_OR_VIEW_NOT_FOUND on constraint DROP during V2 incremental materialization

1 participant