Skip to content

Commit

Permalink
[Fix] safe version attribute access in _check_resource_uniqueness (#7376
Browse files Browse the repository at this point in the history
) (#7405)

safe version attribute access in _check_resource_uniqueness
  • Loading branch information
github-actions[bot] authored Apr 20, 2023
1 parent faa279d commit f0530e6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230418-135257.yaml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 4 additions & 0 deletions core/dbt/contracts/graph/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions core/dbt/graph/selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/unit/test_graph_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test/unit/test_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def _mock_manifest(nodes):
empty=False,
config=config,
fqn=["pkg", n],
is_versioned=False,
)
for n in nodes
}
Expand Down

0 comments on commit f0530e6

Please sign in to comment.