From 18fef38702460d8d1e5c52f5d663f3e12ed27c48 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Thu, 17 Feb 2022 12:15:11 -0500 Subject: [PATCH] Ensure meta is both at node top level and in node.config. Fix snapshots with schema config. (#4726) * Do not overwrite node.meta with empty patch.meta * Restore config_call_dict in snapshot node transform * Test for snapshot with schema file config * Test for meta in both toplevel node and node config --- CHANGELOG.md | 5 +++++ core/dbt/contracts/graph/parsed.py | 1 - core/dbt/parser/snapshots.py | 6 ++++++ .../integration/004_simple_snapshot_tests/models/schema.yml | 3 +++ .../039_config_tests/test_configs_in_schema_files.py | 3 +++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee94915120a..e6b8fb2f912 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## dbt-core 1.1.0 (TBD) +## dbt-core 1.0.3 (TBD) + +### Fixes +- Fix bug causing empty node level meta, snapshot config errors ([#4459](https://github.com/dbt-labs/dbt-core/issues/4459), [#4726](https://github.com/dbt-labs/dbt-core/pull/4726)) + ### Features - Added Support for Semantic Versioning ([#4644](https://github.com/dbt-labs/dbt-core/pull/4644)) - New Dockerfile to support specific db adapters and platforms. See docker/README.md for details ([#4495](https://github.com/dbt-labs/dbt-core/issues/4495), [#4487](https://github.com/dbt-labs/dbt-core/pull/4487)) diff --git a/core/dbt/contracts/graph/parsed.py b/core/dbt/contracts/graph/parsed.py index f5b01af24c7..b3803cb9eda 100644 --- a/core/dbt/contracts/graph/parsed.py +++ b/core/dbt/contracts/graph/parsed.py @@ -157,7 +157,6 @@ def patch(self, patch: "ParsedNodePatch"): self.created_at = time.time() self.description = patch.description self.columns = patch.columns - self.meta = patch.meta self.docs = patch.docs def get_materialization(self): diff --git a/core/dbt/parser/snapshots.py b/core/dbt/parser/snapshots.py index 68b17dd585b..71e7bba955f 100644 --- a/core/dbt/parser/snapshots.py +++ b/core/dbt/parser/snapshots.py @@ -55,8 +55,14 @@ def get_fqn(self, path: str, name: str) -> List[str]: def transform(self, node: IntermediateSnapshotNode) -> ParsedSnapshotNode: try: + # The config_call_dict is not serialized, because normally + # it is not needed after parsing. But since the snapshot node + # does this extra to_dict, save and restore it, to keep + # the model config when there is also schema config. + config_call_dict = node.config_call_dict dct = node.to_dict(omit_none=True) parsed_node = ParsedSnapshotNode.from_dict(dct) + parsed_node.config_call_dict = config_call_dict self.set_snapshot_attributes(parsed_node) return parsed_node except ValidationError as exc: diff --git a/test/integration/004_simple_snapshot_tests/models/schema.yml b/test/integration/004_simple_snapshot_tests/models/schema.yml index 259e55b95fc..6199765d530 100644 --- a/test/integration/004_simple_snapshot_tests/models/schema.yml +++ b/test/integration/004_simple_snapshot_tests/models/schema.yml @@ -3,3 +3,6 @@ snapshots: - name: snapshot_actual tests: - mutually_exclusive_ranges + config: + meta: + owner: 'a_owner' diff --git a/test/integration/039_config_tests/test_configs_in_schema_files.py b/test/integration/039_config_tests/test_configs_in_schema_files.py index 31badb8d041..7cf2df645f4 100644 --- a/test/integration/039_config_tests/test_configs_in_schema_files.py +++ b/test/integration/039_config_tests/test_configs_in_schema_files.py @@ -65,6 +65,9 @@ def test_postgres_config_layering(self): manifest = get_manifest() model_id = 'model.test.model' model_node = manifest.nodes[model_id] + meta_expected = {'company': 'NuMade', 'project': 'test', 'team': 'Core Team', 'owner': 'Julie Smith', 'my_attr': 'TESTING'} + self.assertEqual(model_node.meta, meta_expected) + self.assertEqual(model_node.config.meta, meta_expected) model_tags = ['tag_1_in_model', 'tag_2_in_model', 'tag_in_project', 'tag_in_schema'] model_node_tags = model_node.tags.copy() model_node_tags.sort()