Skip to content

Commit

Permalink
Fix: safe remove of external nodes from nodes.depends_on (#7923)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk authored Jun 22, 2023
1 parent bf15466 commit 6d7b329
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230622-121907.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: 'Fix: safe remove of external nodes from nodes.depends_on'
time: 2023-06-22T12:19:07.657855-04:00
custom:
Author: michelleark
Issue: "7924"
4 changes: 3 additions & 1 deletion core/dbt/parser/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,9 @@ def _process_metrics_for_node(
def remove_dependent_project_references(manifest, external_node_unique_id):
for child_id in manifest.child_map[external_node_unique_id]:
node = manifest.expect(child_id)
node.depends_on_nodes.remove(external_node_unique_id)
# child node may have been modified and already recreated its depends_on.nodes list
if external_node_unique_id in node.depends_on_nodes:
node.depends_on_nodes.remove(external_node_unique_id)
node.created_at = time.time()


Expand Down
12 changes: 12 additions & 0 deletions tests/functional/multi_project/test_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
select * from {{ ref('marketing', 'fct_one') }}
"""

ext_node_model_sql_modified = """
select * from {{ ref('marketing', 'fct_three') }}
"""


class TestPublicationArtifact:
@pytest.fixture(scope="class")
Expand Down Expand Up @@ -203,6 +207,14 @@ def test_pub_artifacts(self, project):
with pytest.raises(TargetNotFoundError):
manifest = run_dbt(["parse"], publications=publications)

# With public node changed from fct_one to fct_three, also update test_model_one's reference
write_file(
ext_node_model_sql_modified, project.project_root, "models", "test_model_one.sql"
)
manifest = run_dbt(["parse"], publications=publications)
# undo test_model_one changes
write_file(ext_node_model_sql, project.project_root, "models", "test_model_one.sql")

# Add another public reference
m_pub_json = m_pub_json.replace("fct_three", "fct_one")
m_pub_json = m_pub_json.replace("04-13", "04-25")
Expand Down

0 comments on commit 6d7b329

Please sign in to comment.