diff --git a/.changes/unreleased/Fixes-20231010-182801.yaml b/.changes/unreleased/Fixes-20231010-182801.yaml new file mode 100644 index 00000000000..50f90b7d746 --- /dev/null +++ b/.changes/unreleased/Fixes-20231010-182801.yaml @@ -0,0 +1,6 @@ +kind: Fixes +body: Override path-like args in dbt retry +time: 2023-10-10T18:28:01.556443+01:00 +custom: + Author: aranke + Issue: "8682" diff --git a/core/dbt/task/retry.py b/core/dbt/task/retry.py index 3a14932aea8..a6ab4e24c9a 100644 --- a/core/dbt/task/retry.py +++ b/core/dbt/task/retry.py @@ -19,6 +19,16 @@ from dbt.task.test import TestTask RETRYABLE_STATUSES = {NodeStatus.Error, NodeStatus.Fail, NodeStatus.Skipped, NodeStatus.RuntimeErr} +OVERRIDE_PARENT_FLAGS = { + "log_path", + "output_path", + "profiles_dir", + "profiles_dir_exists_false", + "project_dir", + "defer_state", + "deprecated_state", + "target_path", +} TASK_DICT = { "build": BuildTask, @@ -91,7 +101,13 @@ def run(self): if k in self.previous_args and v(self.previous_args[k]): del self.previous_args[k] - retry_flags = Flags.from_dict(cli_command, self.previous_args) + previous_args = { + k: v for k, v in self.previous_args.items() if k not in OVERRIDE_PARENT_FLAGS + } + current_args = {k: v for k, v in self.args.__dict__.items() if k in OVERRIDE_PARENT_FLAGS} + combined_args = {**previous_args, **current_args} + + retry_flags = Flags.from_dict(cli_command, combined_args) retry_config = RuntimeConfig.from_args(args=retry_flags) class TaskWrapper(self.task_class): diff --git a/tests/functional/retry/test_retry.py b/tests/functional/retry/test_retry.py index c028bc33f45..c0a8cbc13e4 100644 --- a/tests/functional/retry/test_retry.py +++ b/tests/functional/retry/test_retry.py @@ -1,3 +1,5 @@ +from shutil import copytree, move + import pytest from dbt.contracts.results import RunStatus, TestStatus @@ -271,3 +273,21 @@ def test_resource_type(self, project): # nothing to do results = run_dbt(["retry"]) assert len(results) == 0 + + +class TestRetryOverridePath: + @pytest.fixture(scope="class") + def models(self): + return { + "sample_model.sql": models__sample_model, + } + + def test_retry(self, project): + project_root = project.project_root + proj_location_1 = project_root / "proj_location_1" + proj_location_2 = project_root / "proj_location_2" + + copytree(project_root, proj_location_1) + run_dbt(["run", "--project-dir", "proj_location_1"], expect_pass=False) + move(proj_location_1, proj_location_2) + run_dbt(["retry", "--project-dir", "proj_location_2"], expect_pass=False)