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

schedule child nodes of modified versioned models #7439

Merged
merged 5 commits into from
Apr 25, 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-20230424-164649.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix partial parsing of latest_version changes for downstream references
time: 2023-04-24T16:46:49.721231-04:00
custom:
Author: MichelleArk
Issue: "7369"
3 changes: 3 additions & 0 deletions core/dbt/parser/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,9 @@ def delete_schema_mssa_links(self, schema_file, dict_key, elem):
if self.saved_files[file_id]:
source_file = self.saved_files[file_id]
self.add_to_pp_files(source_file)
# if the node's latest version has changed - need to reparse all referencing nodes to ensure correct ref resolution
if node.is_versioned and node.latest_version != elem.get("latest_version"):
self.schedule_referencing_nodes_for_parsing(elem_unique_id)
# remove from patches
schema_file.node_patches.remove(elem_unique_id)

Expand Down
6 changes: 1 addition & 5 deletions test/unit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,7 @@ def MockNode(package, name, resource_type=None, **kwargs):

version = kwargs.get("version")
search_name = name if version is None else f"{name}.v{version}"
unique_id = (
f"{str(resource_type)}.{package}.{name}"
# if version is None
# else f"{str(resource_type)}.{package}.{name}.v{version}"
)
unique_id = f"{str(resource_type)}.{package}.{name}"
node = mock.MagicMock(
__class__=cls,
resource_type=resource_type,
Expand Down
13 changes: 10 additions & 3 deletions tests/functional/partial_parsing/test_partial_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,36 +304,43 @@ def models(self):
return {
"model_one.sql": model_one_sql,
"model_one_v2.sql": model_one_sql,
"model_one_downstream.sql": model_four2_sql,
"schema.yml": models_versions_schema_yml,
}

def test_pp_versioned_models(self, project):
results = run_dbt(["run"])
assert len(results) == 2
assert len(results) == 3

manifest = get_manifest(project.project_root)
model_one_node = manifest.nodes["model.test.model_one.v1"]
assert not model_one_node.is_latest_version
model_two_node = manifest.nodes["model.test.model_one.v2"]
assert model_two_node.is_latest_version
# assert unpinned ref points to latest version
model_one_downstream_node = manifest.nodes["model.test.model_one_downstream"]
assert model_one_downstream_node.depends_on.nodes == ["model.test.model_one.v2"]

# update versions schema.yml block - latest_version from 2 to 1
write_file(
models_versions_updated_schema_yml, project.project_root, "models", "schema.yml"
)
results = run_dbt(["--partial-parse", "run"])
assert len(results) == 2
assert len(results) == 3

manifest = get_manifest(project.project_root)
model_one_node = manifest.nodes["model.test.model_one.v1"]
assert model_one_node.is_latest_version
model_two_node = manifest.nodes["model.test.model_one.v2"]
assert not model_two_node.is_latest_version
# assert unpinned ref points to latest version
model_one_downstream_node = manifest.nodes["model.test.model_one_downstream"]
assert model_one_downstream_node.depends_on.nodes == ["model.test.model_one.v1"]

# update versioned model
write_file(model_two_sql, project.project_root, "models", "model_one_v2.sql")
results = run_dbt(["--partial-parse", "run"])
assert len(results) == 2
assert len(results) == 3


class TestSources:
Expand Down