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

pass package_name when looking up versioned model node during parsing #8494

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions core/dbt/parser/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
42 changes: 42 additions & 0 deletions tests/functional/duplicates/test_duplicate_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Loading