From fe79715c32bf69f6c351fbb6a7a30908fd9b7890 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 24 Aug 2023 17:38:11 -0400 Subject: [PATCH] pass package_name when looking up versioned model node during parsing --- core/dbt/parser/schemas.py | 4 +- .../duplicates/test_duplicate_model.py | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/core/dbt/parser/schemas.py b/core/dbt/parser/schemas.py index fbc95a73df7..24106a85224 100644 --- a/core/dbt/parser/schemas.py +++ b/core/dbt/parser/schemas.py @@ -693,7 +693,7 @@ def parse_patch(self, block: TargetBlock[UnparsedModelUpdate], refs: ParserRef) ) # ref lookup without version - version is not set yet versioned_model_unique_id = self.manifest.ref_lookup.get_unique_id( - versioned_model_name, None, None + versioned_model_name, target.package_name, None ) versioned_model_node = None @@ -702,7 +702,7 @@ def parse_patch(self, block: TargetBlock[UnparsedModelUpdate], refs: ParserRef) # If this is the latest version, it's allowed to define itself in a model file name that doesn't have a suffix if versioned_model_unique_id is None and unparsed_version.v == latest_version: versioned_model_unique_id = self.manifest.ref_lookup.get_unique_id( - block.name, None, None + block.name, target.package_name, None ) if versioned_model_unique_id is None: diff --git a/tests/functional/duplicates/test_duplicate_model.py b/tests/functional/duplicates/test_duplicate_model.py index 17be1ff20b9..99dd453d429 100644 --- a/tests/functional/duplicates/test_duplicate_model.py +++ b/tests/functional/duplicates/test_duplicate_model.py @@ -44,6 +44,16 @@ """ +local_dep_versions_schema_yml = """ +models: + - name: table_model + config: + alias: table_model_local_dep + versions: + - v: 1 +""" + + class TestDuplicateModelEnabled: @pytest.fixture(scope="class") def models(self): @@ -142,6 +152,38 @@ def test_duplicate_model_disabled_across_packages(self, project): assert model_id in manifest.disabled +class TestDuplicateModelNameWithVersionAcrossPackages: + @pytest.fixture(scope="class", autouse=True) + def setUp(self, project_root): + local_dependency_files = { + "dbt_project.yml": dbt_project_yml, + "models": { + "table_model.sql": enabled_model_sql, + "schema.yml": local_dep_versions_schema_yml, + }, + } + write_project_files(project_root, "local_dependency", local_dependency_files) + + @pytest.fixture(scope="class") + def models(self): + return {"table_model.sql": enabled_model_sql} + + @pytest.fixture(scope="class") + def packages(self): + return {"packages": [{"local": "local_dependency"}]} + + def test_duplicate_model_name_with_test_across_packages(self, project): + run_dbt(["deps"]) + manifest = run_dbt(["parse"]) + assert len(manifest.nodes) == 2 + + # model nodes with duplicate names exist + local_dep_model_node_id = "model.local_dep.table_model.v1" + root_model_node_id = "model.test.table_model" + assert local_dep_model_node_id in manifest.nodes + assert root_model_node_id in manifest.nodes + + class TestModelTestOverlap: @pytest.fixture(scope="class") def models(self):