Skip to content

Fix TypedConstraint equality check #1084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2025
Merged

Fix TypedConstraint equality check #1084

merged 2 commits into from
Jul 7, 2025

Conversation

ericj-db
Copy link
Collaborator

@ericj-db ericj-db commented Jul 3, 2025

Resolves #1081

Description

It looks like the root cause behind #1081 is because of how we determine equality between TypedConstraint objects. During incremental runs, we rely on the equality check to determine which constraints to drop or apply

def get_diff(self, other: "ConstraintsConfig") -> Optional["ConstraintsConfig"]:
# Find constraints that need to be unset
constraints_to_unset = other.set_constraints - self.set_constraints

The current default equality check is considering fields like warn_unenforced. This does not work because this is a user supplied config that has no meaning when we are creating a TypedConstraint from existing Databricks relations. The Fix is to override the __eq__ to match the __hash__ which already ignores such fields

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.

@ericj-db ericj-db requested a review from benc-db as a code owner July 3, 2025 21:59
@benc-db
Copy link
Collaborator

benc-db commented Jul 3, 2025

Wow, great job!

benc-db
benc-db previously approved these changes Jul 3, 2025
Copy link

github-actions bot commented Jul 3, 2025

Coverage report

Click to see where and how coverage changed

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

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

@Korijn
Copy link

Korijn commented Jul 4, 2025

Awesome, happy to see the regression test as well! 🚀

@Korijn
Copy link

Korijn commented Jul 7, 2025

I installed dbt-databricks from this branch and tested locally; this issue seems to be fixed. 🎉

@ericj-db ericj-db merged commit d1e63c3 into main Jul 7, 2025
9 checks passed
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.

Cannot update models with primary & foreign key constraints since version 1.10.2 with MaterializationV2
3 participants