Skip to content

Commit

Permalink
move behaviour flag + test legacy behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Sep 30, 2024
1 parent 6e133bd commit 093be30
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 15 deletions.
40 changes: 25 additions & 15 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,7 @@ def same_contract(self, old, adapter_type=None) -> bool:
return True

def same_vars(self, old) -> bool:
if get_flags().state_modified_compare_vars:
return self.vars == old.vars
else:
return True
return self.vars == old.vars

def same_contents(self, old, adapter_type) -> bool:
if old is None:
Expand All @@ -382,13 +379,20 @@ def same_contents(self, old, adapter_type) -> bool:
# Need to ensure that same_contract is called because it
# could throw an error
same_contract = self.same_contract(old, adapter_type)

# Legacy behaviour
if not get_flags().state_modified_compare_vars:
same_vars = True
else:
same_vars = self.same_vars(old)

return (
self.same_body(old)
and self.same_config(old)
and self.same_persisted_description(old)
and self.same_fqn(old)
and self.same_database_representation(old)
and self.same_vars(old)
and same_vars
and same_contract
and True
)
Expand Down Expand Up @@ -1259,10 +1263,7 @@ def same_config(self, old: "SourceDefinition") -> bool:
)

def same_vars(self, other: "SourceDefinition") -> bool:
if get_flags().state_modified_compare_vars:
return self.vars == other.vars
else:
return True
return self.vars == other.vars

def same_contents(self, old: Optional["SourceDefinition"]) -> bool:
# existing when it didn't before is a change!
Expand All @@ -1277,14 +1278,20 @@ def same_contents(self, old: Optional["SourceDefinition"]) -> bool:
# freshness changes are changes, I guess
# metadata/tags changes are not "changes"
# patching/description changes are not "changes"
# Legacy behaviour
if not get_flags().state_modified_compare_vars:
same_vars = True
else:
same_vars = self.same_vars(old)

return (
self.same_database_representation(old)
and self.same_fqn(old)
and self.same_config(old)
and self.same_quoting(old)
and self.same_freshness(old)
and self.same_external(old)
and self.same_vars(old)
and same_vars
and True
)

Expand Down Expand Up @@ -1382,17 +1389,20 @@ def same_config(self, old: "Exposure") -> bool:
)

def same_vars(self, old: "Exposure") -> bool:
if get_flags().state_modified_compare_vars:
return self.vars == old.vars
else:
return True
return self.vars == old.vars

def same_contents(self, old: Optional["Exposure"]) -> bool:
# existing when it didn't before is a change!
# metadata/tags changes are not "changes"
if old is None:
return True

# Legacy behaviour
if not get_flags().state_modified_compare_vars:
same_vars = True
else:
same_vars = self.same_vars(old)

return (
self.same_fqn(old)
and self.same_exposure_type(old)
Expand All @@ -1403,7 +1413,7 @@ def same_contents(self, old: Optional["Exposure"]) -> bool:
and self.same_label(old)
and self.same_depends_on(old)
and self.same_config(old)
and self.same_vars(old)
and same_vars
and True
)

Expand Down
96 changes: 96 additions & 0 deletions schemas/dbt/manifest/v12.json
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -1745,6 +1751,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -2399,6 +2411,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -3190,6 +3208,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -4000,6 +4024,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -5361,6 +5391,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -6015,6 +6051,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -6973,6 +7015,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -10570,6 +10618,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -11609,6 +11663,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -12263,6 +12323,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -13054,6 +13120,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -13864,6 +13936,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -15225,6 +15303,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -15879,6 +15963,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down Expand Up @@ -16837,6 +16927,12 @@
"type": "string"
}
},
"unrendered_config_call_dict": {
"type": "object",
"propertyNames": {
"type": "string"
}
},
"relation_name": {
"anyOf": [
{
Expand Down
53 changes: 53 additions & 0 deletions tests/functional/defer_state/test_modified_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,59 @@ def test_changed_semantic_model_contents(self, project):
assert len(results) == 1


class TestModifiedVarsLegacy(BaseModifiedState):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"flags": {
"state_modified_compare_vars": False,
},
"vars": {"my_var": 1},
}

@pytest.fixture(scope="class")
def models(self):
return {
"model_with_var.sql": "select {{ var('my_var') }} as id",
}

def test_changed_vars(self, project):
self.run_and_save_state()

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

# Modify var (my_var: 1 -> 2)
update_config_file({"vars": {"my_var": 2}}, "dbt_project.yml")

# By default, do not detect vars in state:modified to preserve legacy behaviour
assert run_dbt(["list", "-s", "state:modified", "--state", "./state"]) == []

# state:modified.vars is a new selector, opt-in method -> returns results
assert run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) == [
"test.model_with_var"
]

# Reset dbt_project.yml
update_config_file({"vars": {"my_var": 1}}, "dbt_project.yml")

# Modify var via --var CLI flag
assert not run_dbt(
["list", "--vars", '{"my_var": 1}', "-s", "state:modified", "--state", "./state"]
)
assert (
run_dbt(
["list", "--vars", '{"my_var": 2}', "-s", "state:modified", "--state", "./state"]
)
== []
)
# state:modified.vars is a new selector, opt-in method -> returns results
assert run_dbt(
["list", "--vars", '{"my_var": 2}', "-s", "state:modified.vars", "--state", "./state"]
) == ["test.model_with_var"]


class TestModifiedVars(BaseModifiedState):
@pytest.fixture(scope="class")
def project_config_update(self):
Expand Down

0 comments on commit 093be30

Please sign in to comment.