Skip to content

Fix: check constraints enforced config param prior to applying#1343

Open
colin-rogers-dbt wants to merge 4 commits intodatabricks:mainfrom
colin-rogers-dbt:colin/fix-primary-key-constraint-enforcement
Open

Fix: check constraints enforced config param prior to applying#1343
colin-rogers-dbt wants to merge 4 commits intodatabricks:mainfrom
colin-rogers-dbt:colin/fix-primary-key-constraint-enforcement

Conversation

@colin-rogers-dbt
Copy link
Contributor

@colin-rogers-dbt colin-rogers-dbt commented Mar 4, 2026

Resolves #1342

Description

Add constraint enforcement checks.

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

@sd-db sd-db changed the title check constraints enforced config param prior to applying Fix: check constraints enforced config param prior to applying Mar 5, 2026
Copy link
Collaborator

@sd-db sd-db left a comment

Choose a reason for hiding this comment

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

One minor comment, we apply constraints in the MV flow as well. From databricks docs this seems purely informational but the behaviour exists and there is even a test to check for this test_create_materialized_view_with_comment_and_constraints. We should apply the guard here + update tests for completeness.

{#- Incremental constraint application requires information_schema access (see fetch_*_constraints macros) -#}
{% if constraints and not target_relation.is_hive_metastore() %}
{% set contract_config = config.get('contract') %}
{% if constraints and contract_config.enforced and not target_relation.is_hive_metastore() %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

let us add a null guard here - {% if constraints and contract_config and contract_config.enforced and not target_relation.is_hive_metastore() %}

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.

Primary key constraint applied without contract

2 participants