diff --git a/.changes/unreleased/Fixes-20231026-002536.yaml b/.changes/unreleased/Fixes-20231026-002536.yaml new file mode 100644 index 00000000000..f14c9ec0e0b --- /dev/null +++ b/.changes/unreleased/Fixes-20231026-002536.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Add version to fqn when version==0 +time: 2023-10-26T00:25:36.259356-05:00 +custom: + Author: aranke + Issue: "8836" diff --git a/core/dbt/contracts/graph/node_args.py b/core/dbt/contracts/graph/node_args.py index d1f4770b184..18b286b2ecc 100644 --- a/core/dbt/contracts/graph/node_args.py +++ b/core/dbt/contracts/graph/node_args.py @@ -33,7 +33,8 @@ def unique_id(self) -> str: @property def fqn(self) -> List[str]: fqn = [self.package_name, self.name] - if self.version: + # Test for None explicitly because version can be 0 + if self.version is not None: fqn.append(f"v{self.version}") return fqn diff --git a/tests/unit/test_contracts_graph_node_args.py b/tests/unit/test_contracts_graph_node_args.py index f3f2d323d9a..958dfa11d72 100644 --- a/tests/unit/test_contracts_graph_node_args.py +++ b/tests/unit/test_contracts_graph_node_args.py @@ -14,7 +14,7 @@ def test_model_node_args_unique_id_with_version(self) -> None: package_name="package", identifier="identifier", schema="schema", - version="1", + version=1, ) assert model_node_args.unique_id == "model.package.name.v1" @@ -33,6 +33,16 @@ def test_model_node_args_fqn_with_version(self) -> None: package_name="package", identifier="identifier", schema="schema", - version="1", + version=1, ) assert model_node_args.fqn == ["package", "name", "v1"] + + def test_model_node_args_fqn_with_version_zero(self) -> None: + model_node_args = ModelNodeArgs( + name="name", + package_name="package", + identifier="identifier", + schema="schema", + version=0, + ) + assert model_node_args.fqn == ["package", "name", "v0"]