diff --git a/.changes/unreleased/Fixes-20230811-204144.yaml b/.changes/unreleased/Fixes-20230811-204144.yaml new file mode 100644 index 00000000000..7295edef0e1 --- /dev/null +++ b/.changes/unreleased/Fixes-20230811-204144.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: fix fqn-selection for external versioned models +time: 2023-08-11T20:41:44.725144-04:00 +custom: + Author: michelleark + Issue: "8374" diff --git a/core/dbt/contracts/graph/node_args.py b/core/dbt/contracts/graph/node_args.py index 09b87a21c50..d1f4770b184 100644 --- a/core/dbt/contracts/graph/node_args.py +++ b/core/dbt/contracts/graph/node_args.py @@ -29,3 +29,11 @@ def unique_id(self) -> str: unique_id = f"{unique_id}.v{self.version}" return unique_id + + @property + def fqn(self) -> List[str]: + fqn = [self.package_name, self.name] + if self.version: + fqn.append(f"v{self.version}") + + return fqn diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index 98f961a0363..3d1fc60a4d1 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -590,7 +590,7 @@ def from_args(cls, args: ModelNodeArgs) -> "ModelNode": name=args.name, package_name=args.package_name, unique_id=unique_id, - fqn=[args.package_name, args.name], + fqn=args.fqn, version=args.version, latest_version=args.latest_version, relation_name=args.relation_name, diff --git a/tests/unit/test_contracts_graph_node_args.py b/tests/unit/test_contracts_graph_node_args.py index 1f632491a21..f3f2d323d9a 100644 --- a/tests/unit/test_contracts_graph_node_args.py +++ b/tests/unit/test_contracts_graph_node_args.py @@ -17,3 +17,22 @@ def test_model_node_args_unique_id_with_version(self) -> None: version="1", ) assert model_node_args.unique_id == "model.package.name.v1" + + def test_model_node_args_fqn(self) -> None: + model_node_args = ModelNodeArgs( + name="name", + package_name="package", + identifier="identifier", + schema="schema", + ) + assert model_node_args.fqn == ["package", "name"] + + def test_model_node_args_fqn_with_version(self) -> None: + model_node_args = ModelNodeArgs( + name="name", + package_name="package", + identifier="identifier", + schema="schema", + version="1", + ) + assert model_node_args.fqn == ["package", "name", "v1"]