Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] safe version attribute access in _check_resource_uniqueness #7376

Merged
merged 4 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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