From b7d7ad2652e0f852332b69c92ec25ebe70c8a95d Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 29 Jul 2024 21:20:18 -0400 Subject: [PATCH] vars at node-level --- core/dbt/artifacts/resources/v1/components.py | 5 +- core/dbt/artifacts/resources/v1/exposure.py | 1 + core/dbt/artifacts/resources/v1/macro.py | 1 + .../resources/v1/source_definition.py | 1 + core/dbt/context/providers.py | 8 +- core/dbt/contracts/graph/nodes.py | 13 +- core/dbt/graph/selector_methods.py | 4 +- core/dbt/parser/macros.py | 4 + schemas/dbt/manifest/v12.json | 240 +++++++----------- .../functional/artifacts/expected_manifest.py | 24 +- .../defer_state/test_modified_state.py | 51 +++- tests/functional/list/test_list.py | 15 +- tests/functional/unit_testing/test_ut_list.py | 2 +- tests/unit/contracts/graph/test_nodes.py | 4 +- .../unit/contracts/graph/test_nodes_parsed.py | 36 ++- 15 files changed, 195 insertions(+), 214 deletions(-) diff --git a/core/dbt/artifacts/resources/v1/components.py b/core/dbt/artifacts/resources/v1/components.py index e93daa5cb4a..539b0629003 100644 --- a/core/dbt/artifacts/resources/v1/components.py +++ b/core/dbt/artifacts/resources/v1/components.py @@ -28,15 +28,11 @@ def add_macro(self, value: str): @dataclass class DependsOn(MacroDependsOn): nodes: List[str] = field(default_factory=list) - vars: Dict[str, Any] = field(default_factory=dict) def add_node(self, value: str): if value not in self.nodes: self.nodes.append(value) - def add_var(self, var_name: str, var_value: Any) -> None: - self.vars[var_name] = var_value - @dataclass class RefArgs(dbtClassMixin): @@ -200,6 +196,7 @@ class ParsedResource(ParsedResourceMandatory): config_call_dict: Dict[str, Any] = field(default_factory=dict) relation_name: Optional[str] = None raw_code: str = "" + vars: Dict[str, Any] = field(default_factory=dict) def __post_serialize__(self, dct: Dict, context: Optional[Dict] = None): dct = super().__post_serialize__(dct, context) diff --git a/core/dbt/artifacts/resources/v1/exposure.py b/core/dbt/artifacts/resources/v1/exposure.py index 00f3c8b89e1..7d8c291381b 100644 --- a/core/dbt/artifacts/resources/v1/exposure.py +++ b/core/dbt/artifacts/resources/v1/exposure.py @@ -41,6 +41,7 @@ class Exposure(GraphResource): tags: List[str] = field(default_factory=list) config: ExposureConfig = field(default_factory=ExposureConfig) unrendered_config: Dict[str, Any] = field(default_factory=dict) + vars: Dict[str, Any] = field(default_factory=dict) url: Optional[str] = None depends_on: DependsOn = field(default_factory=DependsOn) refs: List[RefArgs] = field(default_factory=list) diff --git a/core/dbt/artifacts/resources/v1/macro.py b/core/dbt/artifacts/resources/v1/macro.py index c5154a9a6d4..9220bcf5681 100644 --- a/core/dbt/artifacts/resources/v1/macro.py +++ b/core/dbt/artifacts/resources/v1/macro.py @@ -27,3 +27,4 @@ class Macro(BaseResource): arguments: List[MacroArgument] = field(default_factory=list) created_at: float = field(default_factory=lambda: time.time()) supported_languages: Optional[List[ModelLanguage]] = None + vars: Dict[str, Any] = field(default_factory=dict) diff --git a/core/dbt/artifacts/resources/v1/source_definition.py b/core/dbt/artifacts/resources/v1/source_definition.py index ac0fcfca1b2..d210d4c3dfd 100644 --- a/core/dbt/artifacts/resources/v1/source_definition.py +++ b/core/dbt/artifacts/resources/v1/source_definition.py @@ -68,5 +68,6 @@ class SourceDefinition(ParsedSourceMandatory): config: SourceConfig = field(default_factory=SourceConfig) patch_path: Optional[str] = None unrendered_config: Dict[str, Any] = field(default_factory=dict) + vars: Dict[str, Any] = field(default_factory=dict) relation_name: Optional[str] = None created_at: float = field(default_factory=lambda: time.time()) diff --git a/core/dbt/context/providers.py b/core/dbt/context/providers.py index f6cd6e2230c..7a1f15514a8 100644 --- a/core/dbt/context/providers.py +++ b/core/dbt/context/providers.py @@ -732,12 +732,8 @@ def get_missing_var(self, var_name): def __call__(self, var_name: str, default: Any = ModelConfiguredVar._VAR_NOTSET) -> Any: var_value = super().__call__(var_name, default) - if ( - self._node - and hasattr(self._node, "depends_on") - and hasattr(self._node.depends_on, "add_var") - ): - self._node.depends_on.add_var(var_name, var_value) + if self._node and hasattr(self._node, "vars"): + self._node.vars[var_name] = var_value return var_value diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index b7925dea882..bf85aecd2c7 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -357,6 +357,9 @@ def same_contract(self, old, adapter_type=None) -> bool: # This would only apply to seeds return True + def same_vars(self, old) -> bool: + return self.vars == old.vars + def same_contents(self, old, adapter_type) -> bool: if old is None: return False @@ -370,6 +373,7 @@ def same_contents(self, old, adapter_type) -> bool: and self.same_persisted_description(old) and self.same_fqn(old) and self.same_database_representation(old) + and self.same_vars(old) and same_contract and True ) @@ -409,15 +413,8 @@ def depends_on_nodes(self): def depends_on_macros(self): return self.depends_on.macros - @property - def depends_on_vars(self): - return self.depends_on.vars - - def same_depends_on_vars(self, old): - return self.depends_on_vars == old.depends_on_vars - def same_contents(self, old, adapter_type) -> bool: - return super().same_contents(old, adapter_type) and self.same_depends_on_vars(old) + return super().same_contents(old, adapter_type) # ==================================== diff --git a/core/dbt/graph/selector_methods.py b/core/dbt/graph/selector_methods.py index fcc5f9c02e6..bf3fca19785 100644 --- a/core/dbt/graph/selector_methods.py +++ b/core/dbt/graph/selector_methods.py @@ -623,7 +623,7 @@ def _macros_modified(self) -> List[str]: for uid, macro in new_macros.items(): if uid in old_macros: old_macro = old_macros[uid] - if macro.macro_sql != old_macro.macro_sql: + if macro.macro_sql != old_macro.macro_sql or macro.vars != old_macro.vars: modified.append(uid) else: modified.append(uid) @@ -752,7 +752,7 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu "modified.relation": self.check_modified_factory("same_database_representation"), "modified.macros": self.check_modified_macros, "modified.contract": self.check_modified_contract("same_contract", adapter_type), - "modified.vars": self.check_modified_factory("same_depends_on_vars"), + "modified.vars": self.check_modified_factory("same_vars"), } if selector in state_checks: checker = state_checks[selector] diff --git a/core/dbt/parser/macros.py b/core/dbt/parser/macros.py index f7eaef62b69..6b597dc3dc8 100644 --- a/core/dbt/parser/macros.py +++ b/core/dbt/parser/macros.py @@ -34,6 +34,10 @@ def parse_macro(self, block: jinja.BlockTag, base_node: UnparsedMacro, name: str unique_id = self.generate_unique_id(name) macro_sql = block.full_block or "" + # TODO: + # statically extract potential "vars" calls + # If there are any, create a parse-time macro env + render macro sql to extract vars + return Macro( path=base_node.path, macro_sql=macro_sql, diff --git a/schemas/dbt/manifest/v12.json b/schemas/dbt/manifest/v12.json index 95e0714d8e0..1eece317718 100644 --- a/schemas/dbt/manifest/v12.json +++ b/schemas/dbt/manifest/v12.json @@ -709,6 +709,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "root_path": { "anyOf": [ { @@ -1718,6 +1724,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -1796,12 +1808,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -2372,6 +2378,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -2450,12 +2462,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -3151,6 +3157,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -3229,12 +3241,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -3949,6 +3955,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -4027,12 +4039,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -5259,6 +5265,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -5337,12 +5349,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -5913,6 +5919,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -5991,12 +6003,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -6808,6 +6814,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -6886,12 +6898,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -8333,12 +8339,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -9589,12 +9589,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -10378,6 +10372,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "root_path": { "anyOf": [ { @@ -11387,6 +11387,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -11465,12 +11471,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -12041,6 +12041,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -12119,12 +12125,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -12820,6 +12820,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -12898,12 +12904,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -13618,6 +13618,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -13696,12 +13702,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -14928,6 +14928,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -15006,12 +15012,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -15582,6 +15582,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -15660,12 +15666,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -16477,6 +16477,12 @@ "type": "string", "default": "" }, + "vars": { + "type": "object", + "propertyNames": { + "type": "string" + } + }, "language": { "type": "string", "default": "sql" @@ -16555,12 +16561,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -17791,12 +17791,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -19040,12 +19034,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -19452,12 +19440,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -20112,12 +20094,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -20445,12 +20421,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -20995,12 +20965,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -21662,12 +21626,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false @@ -22002,12 +21960,6 @@ "items": { "type": "string" } - }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } } }, "additionalProperties": false diff --git a/tests/functional/artifacts/expected_manifest.py b/tests/functional/artifacts/expected_manifest.py index ca54bdff4b5..e3fe04a123a 100644 --- a/tests/functional/artifacts/expected_manifest.py +++ b/tests/functional/artifacts/expected_manifest.py @@ -269,7 +269,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "language": "sql", "refs": [{"name": "seed", "package": None, "version": None}], "sources": [], - "depends_on": {"nodes": ["seed.test.seed"], "macros": [], "vars": {}}, + "depends_on": {"nodes": ["seed.test.seed"], "macros": []}, "deprecation_date": None, "unique_id": "model.test.model", "fqn": ["test", "model"], @@ -368,7 +368,7 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "language": "sql", "refs": [{"name": "seed", "package": None, "version": None}], "sources": [], - "depends_on": {"nodes": ["seed.test.seed"], "macros": [], "vars": {}}, + "depends_on": {"nodes": ["seed.test.seed"], "macros": []}, "deprecation_date": None, "unique_id": "model.test.second_model", "fqn": ["test", "second_model"], @@ -546,7 +546,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "depends_on": { "macros": ["macro.dbt.test_not_null", "macro.dbt.get_where_subquery"], "nodes": ["model.test.model"], - "vars": {}, }, "description": "", "file_key_name": "models.model", @@ -600,7 +599,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "depends_on": { "macros": [], "nodes": ["seed.test.seed"], - "vars": {"alternate_schema": alternate_schema}, }, "description": "", "docs": {"node_color": None, "show": True}, @@ -648,7 +646,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "depends_on": { "macros": ["macro.test.test_nothing", "macro.dbt.get_where_subquery"], "nodes": ["model.test.model"], - "vars": {}, }, "description": "", "file_key_name": "models.model", @@ -701,7 +698,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "depends_on": { "macros": ["macro.dbt.test_unique", "macro.dbt.get_where_subquery"], "nodes": ["model.test.model"], - "vars": {}, }, "description": "", "file_key_name": "models.model", @@ -800,7 +796,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "depends_on": { "macros": [], "nodes": ["model.test.model", "model.test.second_model"], - "vars": {}, }, "description": "A description of the complex exposure\n", "label": None, @@ -833,7 +828,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "depends_on": { "macros": [], "nodes": ["source.test.my_source.my_table", "model.test.model"], - "vars": {}, }, "description": "", "label": None, @@ -947,7 +941,6 @@ def expected_references_manifest(project): "depends_on": { "macros": [], "nodes": ["source.test.my_source.my_table"], - "vars": {}, }, "deprecation_date": None, "description": "", @@ -1017,7 +1010,6 @@ def expected_references_manifest(project): "depends_on": { "macros": [], "nodes": ["model.test.ephemeral_copy"], - "vars": {}, }, "deprecation_date": None, "description": "A summmary table of the ephemeral copy of the seed data", @@ -1090,7 +1082,6 @@ def expected_references_manifest(project): "depends_on": { "macros": [], "nodes": ["model.test.ephemeral_summary"], - "vars": {}, }, "deprecation_date": None, "description": "A view of the summary of the ephemeral copy of the seed data", @@ -1220,7 +1211,6 @@ def expected_references_manifest(project): "depends_on": { "macros": [], "nodes": ["seed.test.seed"], - "vars": {"alternate_schema": alternate_schema}, }, "description": "", "docs": {"node_color": None, "show": True}, @@ -1310,7 +1300,6 @@ def expected_references_manifest(project): "depends_on": { "macros": [], "nodes": ["model.test.view_summary"], - "vars": {}, }, "description": "A description of the complex exposure", "label": None, @@ -1552,7 +1541,7 @@ def expected_versions_manifest(project): ), "constraints": [], "sources": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "description": "A versioned model", "primary_key": ["count", "first_name"], "deprecation_date": ANY, @@ -1626,7 +1615,7 @@ def expected_versions_manifest(project): "constraints": [], "contract": {"checksum": None, "enforced": False, "alias_types": True}, "sources": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "description": "A versioned model", "primary_key": ["first_name"], "deprecation_date": None, @@ -1680,7 +1669,6 @@ def expected_versions_manifest(project): "model.test.versioned_model.v2", "model.test.versioned_model.v1", ], - "vars": {}, }, "deprecation_date": None, "description": "", @@ -1740,7 +1728,6 @@ def expected_versions_manifest(project): "depends_on": { "macros": ["macro.dbt.test_unique", "macro.dbt.get_where_subquery"], "nodes": ["model.test.versioned_model.v1"], - "vars": {}, }, "description": "", "file_key_name": "models.versioned_model", @@ -1794,7 +1781,6 @@ def expected_versions_manifest(project): "depends_on": { "macros": ["macro.dbt.test_unique", "macro.dbt.get_where_subquery"], "nodes": ["model.test.versioned_model.v1"], - "vars": {}, }, "description": "", "file_key_name": "models.versioned_model", @@ -1848,7 +1834,6 @@ def expected_versions_manifest(project): "depends_on": { "macros": ["macro.dbt.test_unique", "macro.dbt.get_where_subquery"], "nodes": ["model.test.versioned_model.v2"], - "vars": {}, }, "description": "", "file_key_name": "models.versioned_model", @@ -1892,7 +1877,6 @@ def expected_versions_manifest(project): "depends_on": { "macros": [], "nodes": ["model.test.versioned_model.v2"], - "vars": {}, }, "description": "notebook_info", "label": None, diff --git a/tests/functional/defer_state/test_modified_state.py b/tests/functional/defer_state/test_modified_state.py index 86d2e5af2d8..5f34280c64f 100644 --- a/tests/functional/defer_state/test_modified_state.py +++ b/tests/functional/defer_state/test_modified_state.py @@ -1156,7 +1156,7 @@ def project_config_update(self): @pytest.fixture(scope="class") def models(self): return { - "view_model.sql": "select {{ var('my_var') }} as id", + "model_with_var.sql": "select {{ var('my_var') }} as id", } def test_changed_vars(self, project): @@ -1169,10 +1169,10 @@ def test_changed_vars(self, project): # Modify var (my_var: 1 -> 2) update_config_file({"vars": {"my_var": 2}}, "dbt_project.yml") assert run_dbt(["list", "-s", "state:modified", "--state", "./state"]) == [ - "test.view_model" + "test.model_with_var" ] assert run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) == [ - "test.view_model" + "test.model_with_var" ] # Reset dbt_project.yml @@ -1184,4 +1184,47 @@ def test_changed_vars(self, project): ) assert run_dbt( ["list", "--vars", '{"my_var": 2}', "-s", "state:modified", "--state", "./state"] - ) == ["test.view_model"] + ) == ["test.model_with_var"] + + +macro_with_var_sql = """ +{% macro macro_with_var() %} + {{ var('my_var') }} +{% endmacro %} +""" + + +class TestModifiedMacroVars(BaseModifiedState): + @pytest.fixture(scope="class") + def project_config_update(self): + return { + "vars": {"my_var": 1}, + } + + @pytest.fixture(scope="class") + def models(self): + return { + "model_with_macro.sql": "select {{ macro_with_var() }} as id", + } + + @pytest.fixture(scope="class") + def macros(self): + return { + "macro_with_var.sql": macro_with_var_sql, + } + + 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") + assert run_dbt(["list", "-s", "state:modified", "--state", "./state"]) == [ + "test.model_with_macro" + ] + assert run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) == [ + "test.model_with_macro" + ] diff --git a/tests/functional/list/test_list.py b/tests/functional/list/test_list.py index 06dec525e82..19a7a11c50f 100644 --- a/tests/functional/list/test_list.py +++ b/tests/functional/list/test_list.py @@ -52,7 +52,6 @@ def expect_snapshot_output(self, happy_path_project): # noqa: F811 "depends_on": { "nodes": [], "macros": [], - "vars": {"target_database": happy_path_project.database}, }, "tags": [], "config": { @@ -100,7 +99,7 @@ def expect_analyses_output(self): "json": { "name": "a", "package_name": "test", - "depends_on": {"nodes": [], "macros": [], "vars": {}}, + "depends_on": {"nodes": [], "macros": []}, "tags": [], "config": { "enabled": True, @@ -160,7 +159,6 @@ def expect_model_output(self): "depends_on": { "nodes": [], "macros": ["macro.dbt.current_timestamp", "macro.dbt.date_trunc"], - "vars": {}, }, "tags": [], "config": { @@ -199,7 +197,6 @@ def expect_model_output(self): "depends_on": { "nodes": ["seed.test.seed"], "macros": ["macro.dbt.is_incremental"], - "vars": {}, }, "tags": [], "config": { @@ -238,7 +235,6 @@ def expect_model_output(self): "depends_on": { "nodes": ["model.test.outer"], "macros": [], - "vars": {}, }, "tags": [], "config": { @@ -277,7 +273,6 @@ def expect_model_output(self): "depends_on": { "nodes": [], "macros": ["macro.dbt.current_timestamp", "macro.dbt.date_trunc"], - "vars": {}, }, "tags": [], "config": { @@ -316,7 +311,6 @@ def expect_model_output(self): "depends_on": { "nodes": [], "macros": ["macro.dbt.current_timestamp", "macro.dbt.date_trunc"], - "vars": {}, }, "tags": [], "config": { @@ -355,7 +349,6 @@ def expect_model_output(self): "depends_on": { "nodes": ["model.test.ephemeral"], "macros": [], - "vars": {}, }, "tags": [], "config": { @@ -409,7 +402,7 @@ def expect_model_ephemeral_output(self): { "name": "outer", "package_name": "test", - "depends_on": {"nodes": [], "macros": [], "vars": {}}, + "depends_on": {"nodes": [], "macros": []}, "tags": [], "config": { "enabled": True, @@ -522,7 +515,6 @@ def expect_test_output(self): "depends_on": { "nodes": ["model.test.outer"], "macros": ["macro.dbt.test_not_null"], - "vars": {}, }, "tags": [], "config": { @@ -551,7 +543,7 @@ def expect_test_output(self): { "name": "t", "package_name": "test", - "depends_on": {"nodes": [], "macros": [], "vars": {}}, + "depends_on": {"nodes": [], "macros": []}, "tags": [], "config": { "enabled": True, @@ -582,7 +574,6 @@ def expect_test_output(self): "depends_on": { "nodes": ["model.test.outer"], "macros": ["macro.dbt.test_unique"], - "vars": {}, }, "tags": [], "config": { diff --git a/tests/functional/unit_testing/test_ut_list.py b/tests/functional/unit_testing/test_ut_list.py index 309f07743e0..0b4f263909b 100644 --- a/tests/functional/unit_testing/test_ut_list.py +++ b/tests/functional/unit_testing/test_ut_list.py @@ -58,7 +58,7 @@ def test_unit_test_list(self, project): "package_name": "test", "original_file_path": os.path.join("models", "test_my_model.yml"), "unique_id": "unit_test.test.my_model.test_my_model", - "depends_on": {"macros": [], "nodes": ["model.test.my_model"], "vars": {}}, + "depends_on": {"macros": [], "nodes": ["model.test.my_model"]}, "config": {"tags": [], "meta": {}}, } for result in results: diff --git a/tests/unit/contracts/graph/test_nodes.py b/tests/unit/contracts/graph/test_nodes.py index b69d3d30313..a498b99dcbc 100644 --- a/tests/unit/contracts/graph/test_nodes.py +++ b/tests/unit/contracts/graph/test_nodes.py @@ -159,7 +159,7 @@ def basic_compiled_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "database": "test_db", "description": "", "primary_key": [], @@ -478,7 +478,7 @@ def basic_compiled_schema_test_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "database": "test_db", "description": "", "schema": "dbt_test__audit", diff --git a/tests/unit/contracts/graph/test_nodes_parsed.py b/tests/unit/contracts/graph/test_nodes_parsed.py index 98189ea7239..c3de2b55397 100644 --- a/tests/unit/contracts/graph/test_nodes_parsed.py +++ b/tests/unit/contracts/graph/test_nodes_parsed.py @@ -163,7 +163,7 @@ def base_parsed_model_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "database": "test_db", "description": "", "primary_key": [], @@ -197,6 +197,7 @@ def base_parsed_model_dict(): "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", }, "unrendered_config": {}, + "vars": {}, "config_call_dict": {}, "access": AccessType.Protected.value, "constraints": [], @@ -253,6 +254,7 @@ def minimal_parsed_model_dict(): "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", }, "unrendered_config": {}, + "vars": {}, } @@ -272,7 +274,7 @@ def complex_parsed_model_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": ["model.test.bar"], "vars": {}}, + "depends_on": {"macros": [], "nodes": ["model.test.bar"]}, "database": "test_db", "description": "My parsed node", "primary_key": [], @@ -318,6 +320,7 @@ def complex_parsed_model_dict(): "materialized": "ephemeral", "post_hook": ['insert into blah(a, b) select "1", 1'], }, + "vars": {}, "config_call_dict": {}, "access": AccessType.Protected.value, "constraints": [], @@ -526,6 +529,7 @@ def basic_parsed_seed_dict(): "meta": {}, "checksum": {"name": "path", "checksum": "seeds/seed.csv"}, "unrendered_config": {}, + "vars": {}, "config_call_dict": {}, } @@ -630,6 +634,7 @@ def complex_parsed_seed_dict(): "unrendered_config": { "persist_docs": {"relation": True, "columns": True}, }, + "vars": {}, "config_call_dict": {}, } @@ -796,7 +801,7 @@ def base_parsed_hook_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "database": "test_db", "description": "", "schema": "test_schema", @@ -828,6 +833,7 @@ def base_parsed_hook_dict(): "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", }, "unrendered_config": {}, + "vars": {}, "config_call_dict": {}, } @@ -876,7 +882,7 @@ def complex_parsed_hook_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": ["model.test.bar"], "vars": {}}, + "depends_on": {"macros": [], "nodes": ["model.test.bar"]}, "database": "test_db", "description": "My parsed node", "schema": "test_schema", @@ -920,6 +926,7 @@ def complex_parsed_hook_dict(): "column_types": {"a": "text"}, "materialized": "table", }, + "vars": {}, "config_call_dict": {}, } @@ -1033,7 +1040,7 @@ def basic_parsed_schema_test_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "database": "test_db", "description": "", "schema": "test_schema", @@ -1063,6 +1070,7 @@ def basic_parsed_schema_test_dict(): "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", }, "unrendered_config": {}, + "vars": {}, "config_call_dict": {}, } @@ -1111,7 +1119,7 @@ def complex_parsed_schema_test_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": ["model.test.bar"], "vars": {}}, + "depends_on": {"macros": [], "nodes": ["model.test.bar"]}, "database": "test_db", "description": "My parsed node", "schema": "test_schema", @@ -1151,6 +1159,7 @@ def complex_parsed_schema_test_dict(): "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", }, "unrendered_config": {"materialized": "table", "severity": "WARN"}, + "vars": {}, "config_call_dict": {}, } @@ -1492,7 +1501,7 @@ def basic_timestamp_snapshot_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "database": "test_db", "description": "", "schema": "test_schema", @@ -1535,6 +1544,7 @@ def basic_timestamp_snapshot_dict(): "target_database": "some_snapshot_db", "target_schema": "some_snapshot_schema", }, + "vars": {}, "config_call_dict": {}, } @@ -1594,7 +1604,7 @@ def basic_check_snapshot_dict(): "refs": [], "sources": [], "metrics": [], - "depends_on": {"macros": [], "nodes": [], "vars": {}}, + "depends_on": {"macros": [], "nodes": []}, "database": "test_db", "description": "", "schema": "test_schema", @@ -1638,6 +1648,7 @@ def basic_check_snapshot_dict(): "check_cols": "all", }, "config_call_dict": {}, + "vars": {}, } @@ -1730,6 +1741,7 @@ def _ok_dict(self): "description": "my macro description", "docs": {"show": True}, "arguments": [], + "vars": {}, } def test_ok(self): @@ -1746,6 +1758,7 @@ def test_ok(self): meta={}, description="my macro description", arguments=[], + vars={}, ) assert_symmetric(macro, macro_dict) pickle.loads(pickle.dumps(macro)) @@ -1847,6 +1860,7 @@ def basic_parsed_source_definition_dict(): "enabled": True, }, "unrendered_config": {}, + "vars": {}, } @@ -1879,6 +1893,7 @@ def complex_parsed_source_definition_dict(): "freshness": {"warn_after": {"period": "hour", "count": 1}, "error_after": {}}, "loaded_at_field": "loaded_at", "unrendered_config": {}, + "vars": {}, } @@ -2033,7 +2048,6 @@ def basic_parsed_exposure_dict(): "depends_on": { "nodes": [], "macros": [], - "vars": {}, }, "refs": [], "sources": [], @@ -2051,6 +2065,7 @@ def basic_parsed_exposure_dict(): "enabled": True, }, "unrendered_config": {}, + "vars": {}, } @@ -2093,7 +2108,6 @@ def complex_parsed_exposure_dict(): "depends_on": { "nodes": ["models.test.my_model"], "macros": [], - "vars": {}, }, "refs": [], "sources": [], @@ -2107,6 +2121,7 @@ def complex_parsed_exposure_dict(): "enabled": True, }, "unrendered_config": {}, + "vars": {}, } @@ -2219,7 +2234,6 @@ def basic_parsed_metric_dict(): "depends_on": { "nodes": [], "macros": [], - "vars": {}, }, }