Skip to content

fix: gate column-level constraints on contract.enforced (#1381)#1470

Merged
sd-db merged 10 commits into
mainfrom
sd-db/fix/dbt-1381-column-constraint-leak
Jun 3, 2026
Merged

fix: gate column-level constraints on contract.enforced (#1381)#1470
sd-db merged 10 commits into
mainfrom
sd-db/fix/dbt-1381-column-constraint-leak

Conversation

@sd-db

@sd-db sd-db commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #1381. Completes the contract-enforcement work from #1342 / #1343 for the column-level subpath.

Under use_materialization_v2: true without contract.enforced: true, the macro-layer gate stripped model-level constraints but left column-level ones untouched — they flowed through parse_columns_and_constraints into CREATE TABLE

Breaking for anyone relying on the leak — column-level NOT NULL / PK / FK on V2 now requires contract.enforced: true. Called out in CHANGELOG.

Test plan

  • Unit: TestParseColumnsAndConstraintsGate in tests/unit/test_constraints.py (4 cases)
  • Functional: tests/functional/adapter/constraints/test_column_constraint_gate.py — gated and ungated paths against a live cluster
  • Full constraint regression sweep — 43 passed, 0 failed
  • Pre-commit clean

`adapter.parse_columns_and_constraints` gains a `contract_enforced` flag
so the column-level subpath honors the same gate that already applies to
the model-level subpath and the diff path. The three V2 create macros
(`table`, `materialized_view`, `streaming_table`) compute `contract.enforced`
once and pass it in.

Pre-fix, under `use_materialization_v2: true` without `contract.enforced:
true`, column-level NOT NULL / FK leaked through and were applied to the
table, while model-level constraints (e.g. multi-column PK) were correctly
gated out. On incremental re-runs the diff path then "cleaned up" the leaked
constraints, emitting `DROP CONSTRAINT IF EXISTS` with no follow-up
`ADD CONSTRAINT` — silently stripping constraints on every successive run.

Closes #1381. Completes the contract-enforcement work from #1342/#1343.
@sd-db sd-db requested a review from jprakash-db as a code owner May 20, 2026 06:40
@github-actions

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks
  impl.py
Project Total  

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

@sd-db

sd-db commented May 20, 2026

Copy link
Copy Markdown
Collaborator Author

/integration-test

@github-actions

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

Run details.

The not_null on id was being applied silently via the pre-PR leak.
With column-level constraints now gated by contract.enforced, the
fixture must opt in explicitly to keep test_streaming_table_create
asserting that the constraint reaches the database.

Mirrors the existing materialized_view_schema fixture.

@jprakash-db jprakash-db left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for making the changes

sd-db added 7 commits May 22, 2026 21:17
When a model declares column-level constraints but does not set
contract.enforced: true, parse_columns_and_constraints now emits a
targeted info-level log naming the model, instead of silently dropping
the constraints. Fires only when constraints are actually declared, so
it stays quiet for models without constraints or with enforcement on.

Threads model.name through the three V2 create macros (table,
materialized_view, streaming_table).
- Drop redundant log-message assertion in the skip-logs test;
  assert_called_once() is sufficient.
- Remove the info-log note from the BREAKING changelog line.
@sd-db sd-db merged commit c1c74df into main Jun 3, 2026
9 checks passed
@sd-db sd-db deleted the sd-db/fix/dbt-1381-column-constraint-leak branch June 3, 2026 05:15
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.

Setting Constraints (PK/FK) not working properly

2 participants