Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoop committed May 25, 2023
1 parent d4e3f8e commit e718c43
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230525-073651.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Improve warnings for constraints and materialization types
time: 2023-05-25T07:36:51.855641-05:00
custom:
Author: emmyoop
Issue: "7335"
5 changes: 4 additions & 1 deletion core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,10 @@ def patch_constraints(self, node, constraints):
if contract_config.enforced is True:
self._validate_constraint_prerequisites(node)

if node.config.materialized not in ["table", "incremental"] and constraints:
breakpoint()
if any(
c for c in constraints if c.get("warn_unsupported")
) and node.config.materialized not in ["table", "incremental"]:
warn_or_error(
UnsupportedConstraintMaterialization(materialization=node.config.materialized),
node=node,
Expand Down
3 changes: 2 additions & 1 deletion plugins/postgres/dbt/adapters/postgres/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class PostgresAdapter(SQLAdapter):
ConstraintType.check: ConstraintSupport.ENFORCED,
ConstraintType.not_null: ConstraintSupport.ENFORCED,
ConstraintType.unique: ConstraintSupport.ENFORCED,
ConstraintType.primary_key: ConstraintSupport.ENFORCED,
# ConstraintType.primary_key: ConstraintSupport.ENFORCED,
ConstraintType.primary_key: ConstraintSupport.NOT_SUPPORTED,
ConstraintType.foreign_key: ConstraintSupport.ENFORCED,
}

Expand Down
15 changes: 8 additions & 7 deletions tests/functional/configs/test_contract_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,16 @@ def models(self):
}

def test__config_errors(self, project):
with pytest.raises(ParsingError) as err_info:
run_dbt(["run"], expect_pass=False)
# result = run_dbt(["run"])
_, log_output = run_dbt_and_capture(["run"])
# breakpoint()

exc_str = " ".join(str(err_info.value).split())
expected_materialization_error = "Only table, view, and incremental materializations are supported for constraints, but found 'ephemeral'"
assert expected_materialization_error in str(exc_str)
# exc_str = " ".join(str(err_info.value).split())
# expected_materialization_error = "Only table, view, and incremental materializations are supported for constraints, but found 'ephemeral'"
# assert expected_materialization_error in str(exc_str)
# This is a compile time error and we won't get here because the materialization check is parse time
expected_empty_data_type_error = "Columns with `data_type` Blank/Null not allowed on contracted models. Columns Blank/Null: ['date_day']"
assert expected_empty_data_type_error not in str(exc_str)
# expected_empty_data_type_error = "Columns with `data_type` Blank/Null not allowed on contracted models. Columns Blank/Null: ['date_day']"
# assert expected_empty_data_type_error not in str(exc_str)


class TestSchemaContractEnabledConfigs:
Expand Down

0 comments on commit e718c43

Please sign in to comment.