Skip to content

Commit

Permalink
simplify access check, add deprecation_date modification detection
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Aug 7, 2023
1 parent 9217526 commit 8e171b8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 53 deletions.
10 changes: 4 additions & 6 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,11 @@ def same_contents(self, old, adapter_type) -> bool:

def same_ref_representation(self, old) -> bool:
return (
# Changing a version may break downstream refs
self.version == old.version
# Changing the latest_version may break downstream unpinned refs
and self.latest_version == old.latest_version
# Tightening (reducing) access may break downstream refs;
# increasing or no change implies same ref representation
and self.access >= old.access
self.latest_version == old.latest_version
# Changes to access or deprecation_date may lead to ref-related parsing errors
and self.access == old.access
and self.deprecation_date == old.deprecation_date
)

def build_contract_checksum(self):
Expand Down
7 changes: 0 additions & 7 deletions core/dbt/node_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ def is_valid(cls, item):
return False
return True

def __lt__(self, other):
if not isinstance(other, AccessType):
raise NotImplementedError

members = list(AccessType)
return members.index(self) < members.index(other)


class NodeType(StrEnum):
Model = "model"
Expand Down
41 changes: 25 additions & 16 deletions tests/functional/defer_state/test_modified_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,44 +783,53 @@ def test_modified_body_and_contract(self, project):
assert results == ["test.my_model"]


modified_my_model_widen_access_yml = """
modified_table_model_access_yml = """
version: 2
models:
- name: table_model
access: public
"""

modified_my_model_tighten_access_yml = """

class TestModifiedAccess(BaseModifiedState):
def test_changed_access(self, project):
self.run_and_save_state()

# No access change
assert not run_dbt(["list", "-s", "state:modified", "--state", "./state"])

# Modify access (protected -> public)
write_file(modified_table_model_access_yml, "models", "schema.yml")
assert run_dbt(["list", "-s", "state:modified", "--state", "./state"])

results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert results == ["test.table_model"]


modified_table_model_access_yml = """
version: 2
groups:
- name: my_group
owner: {name: my_group_owner}
models:
- name: table_model
access: private
group: my_group
deprecation_date: 2020-01-01
"""


class TestModifiedAccess(BaseModifiedState):
class TestModifiedDeprecationDate(BaseModifiedState):
def test_changed_access(self, project):
self.run_and_save_state()

# No access change
assert not run_dbt(["list", "-s", "state:modified", "--state", "./state"])

# Tighten access (protected -> public)
write_file(modified_my_model_widen_access_yml, "models", "schema.yml")
assert not run_dbt(["list", "-s", "state:modified", "--state", "./state"])

# Tighten access (protected -> private)
write_file(modified_my_model_tighten_access_yml, "models", "schema.yml")
# Modify deprecation_date (None -> 2020-01-01)
write_file(modified_table_model_access_yml, "models", "schema.yml")
assert run_dbt(["list", "-s", "state:modified", "--state", "./state"])

results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert results == ["test.table_model"]


modified_my_model_version_yml = """
modified_table_model_version_yml = """
version: 2
models:
- name: table_model
Expand All @@ -835,7 +844,7 @@ def test_changed_access(self, project):
self.run_and_save_state()

# Change version (null -> v1)
write_file(modified_my_model_version_yml, "models", "schema.yml")
write_file(modified_table_model_version_yml, "models", "schema.yml")

results = run_dbt(["list", "-s", "state:modified", "--state", "./state"])
assert results == ["test.table_model.v1"]
Expand Down
22 changes: 0 additions & 22 deletions tests/unit/test_access.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/unit/test_contracts_graph_parsed.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ def test_invalid_bad_materialized(base_parsed_model_dict):
lambda u: (u, u.replace(alias="other")),
lambda u: (u, u.replace(schema="other")),
lambda u: (u, u.replace(database="other")),
# unchanged ref representations
lambda u: (u, u.replace(access=AccessType.Private)),
# unchanged ref representations - protected is default
lambda u: (u, u.replace(access=AccessType.Protected)),
]


Expand Down

0 comments on commit 8e171b8

Please sign in to comment.