diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index 6c589f11cf5..dea8af5bf37 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -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: @@ -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 ) @@ -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! @@ -1277,6 +1278,12 @@ 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) @@ -1284,7 +1291,7 @@ def same_contents(self, old: Optional["SourceDefinition"]) -> bool: 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 ) @@ -1382,10 +1389,7 @@ 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! @@ -1393,6 +1397,12 @@ def same_contents(self, old: Optional["Exposure"]) -> bool: 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) @@ -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 ) diff --git a/schemas/dbt/manifest/v12.json b/schemas/dbt/manifest/v12.json index ea21214b4fc..3527e4d8136 100644 --- a/schemas/dbt/manifest/v12.json +++ b/schemas/dbt/manifest/v12.json @@ -706,6 +706,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -1745,6 +1751,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -2399,6 +2411,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -3190,6 +3208,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -4000,6 +4024,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -5361,6 +5391,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -6015,6 +6051,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -6973,6 +7015,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -10570,6 +10618,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -11609,6 +11663,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -12263,6 +12323,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -13054,6 +13120,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -13864,6 +13936,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -15225,6 +15303,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -15879,6 +15963,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { @@ -16837,6 +16927,12 @@ "type": "string" } }, + "unrendered_config_call_dict": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "relation_name": { "anyOf": [ { diff --git a/tests/functional/defer_state/test_modified_state.py b/tests/functional/defer_state/test_modified_state.py index 2fe52584b51..3d0f0955c93 100644 --- a/tests/functional/defer_state/test_modified_state.py +++ b/tests/functional/defer_state/test_modified_state.py @@ -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):