From 760e8fae5640e093aebbb55971335d7db9390d5b Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 17 Apr 2023 18:21:53 -0400 Subject: [PATCH 1/3] safe version attribute access in _check_resource_uniqueness --- core/dbt/contracts/graph/nodes.py | 4 ++++ core/dbt/parser/manifest.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index ff11b489dff..ec2a218d50f 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -119,6 +119,10 @@ def should_store_failures(self): def is_relational(self): return self.resource_type in NodeType.refable() + @property + def is_versioned(self): + return self.resource_type in NodeType.versioned() and self.version is not None + @property def is_ephemeral(self): return self.config.materialized == "ephemeral" diff --git a/core/dbt/parser/manifest.py b/core/dbt/parser/manifest.py index 227d434bff9..d17d171e315 100644 --- a/core/dbt/parser/manifest.py +++ b/core/dbt/parser/manifest.py @@ -1106,7 +1106,7 @@ def _check_resource_uniqueness( full_node_name = str(relation) existing_node = names_resources.get(name) - if existing_node is not None and existing_node.version is None: + if existing_node is not None and not existing_node.is_versioned: raise dbt.exceptions.DuplicateResourceNameError(existing_node, node) existing_alias = alias_resources.get(full_node_name) From ee6856a4016216965a17ed3483277794e8d8316d Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 17 Apr 2023 18:22:38 -0400 Subject: [PATCH 2/3] refactor QualifiedNameSelectorMethod.search to use is_versioned property --- core/dbt/graph/selector_methods.py | 3 +-- test/unit/test_graph_selection.py | 1 + test/unit/test_linker.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/dbt/graph/selector_methods.py b/core/dbt/graph/selector_methods.py index 3d4a7a32afb..e3139355d7a 100644 --- a/core/dbt/graph/selector_methods.py +++ b/core/dbt/graph/selector_methods.py @@ -210,8 +210,7 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu """ parsed_nodes = list(self.parsed_nodes(included_nodes)) for node, real_node in parsed_nodes: - is_versioned = isinstance(real_node, ModelNode) and real_node.version is not None - if self.node_is_match(selector, real_node.fqn, is_versioned): + if self.node_is_match(selector, real_node.fqn, real_node.is_versioned): yield node diff --git a/test/unit/test_graph_selection.py b/test/unit/test_graph_selection.py index aeefa2fea9d..572c8fed10d 100644 --- a/test/unit/test_graph_selection.py +++ b/test/unit/test_graph_selection.py @@ -42,6 +42,7 @@ def _get_manifest(graph): resource_type=NodeType.Model, empty=False, config=mock.MagicMock(enabled=True), + is_versioned=False, ) nodes[unique_id] = node diff --git a/test/unit/test_linker.py b/test/unit/test_linker.py index 7eb74616f80..9c36ae19674 100644 --- a/test/unit/test_linker.py +++ b/test/unit/test_linker.py @@ -25,6 +25,7 @@ def _mock_manifest(nodes): empty=False, config=config, fqn=["pkg", n], + is_versioned=False, ) for n in nodes } From 45ced5d8bce4bbf5143d2e466b040f57d736b54c Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Tue, 18 Apr 2023 13:53:03 -0400 Subject: [PATCH 3/3] changelog entry --- .changes/unreleased/Fixes-20230418-135257.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Fixes-20230418-135257.yaml diff --git a/.changes/unreleased/Fixes-20230418-135257.yaml b/.changes/unreleased/Fixes-20230418-135257.yaml new file mode 100644 index 00000000000..9f3c6a197b2 --- /dev/null +++ b/.changes/unreleased/Fixes-20230418-135257.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: safe version attribute access in _check_resource_uniqueness +time: 2023-04-18T13:52:57.367108-04:00 +custom: + Author: MichelleArk + Issue: "7375"