From 6d7b32977c8a18b859b7c3a8021f2afe980ecffa Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 22 Jun 2023 10:42:06 -0700 Subject: [PATCH] Fix: safe remove of external nodes from nodes.depends_on (#7923) --- .changes/unreleased/Fixes-20230622-121907.yaml | 6 ++++++ core/dbt/parser/manifest.py | 4 +++- tests/functional/multi_project/test_publication.py | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Fixes-20230622-121907.yaml diff --git a/.changes/unreleased/Fixes-20230622-121907.yaml b/.changes/unreleased/Fixes-20230622-121907.yaml new file mode 100644 index 00000000000..f2893cbfef7 --- /dev/null +++ b/.changes/unreleased/Fixes-20230622-121907.yaml @@ -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" diff --git a/core/dbt/parser/manifest.py b/core/dbt/parser/manifest.py index 42a8138468b..96030aea79b 100644 --- a/core/dbt/parser/manifest.py +++ b/core/dbt/parser/manifest.py @@ -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() diff --git a/tests/functional/multi_project/test_publication.py b/tests/functional/multi_project/test_publication.py index 4283379de86..24d9b8cca5a 100644 --- a/tests/functional/multi_project/test_publication.py +++ b/tests/functional/multi_project/test_publication.py @@ -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") @@ -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")