From 0976050ed3ca8b297a3e9c91aadc0f82b5d65044 Mon Sep 17 00:00:00 2001 From: Justin Bandoro Date: Wed, 15 Nov 2023 15:55:41 -0800 Subject: [PATCH 1/2] fix: test_load_via_dbt_ls_with_invalid_dbt_path if user has system dbt --- cosmos/config.py | 4 +++- tests/dbt/test_graph.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cosmos/config.py b/cosmos/config.py index 57d5200b15..f9d47f5e2e 100644 --- a/cosmos/config.py +++ b/cosmos/config.py @@ -258,7 +258,7 @@ class ExecutionConfig: execution_mode: ExecutionMode = ExecutionMode.LOCAL test_indirect_selection: TestIndirectSelection = TestIndirectSelection.EAGER - dbt_executable_path: str | Path = get_system_dbt() + dbt_executable_path: str | Path | None = None dbt_project_path: InitVar[str | Path | None] = None @@ -266,3 +266,5 @@ class ExecutionConfig: def __post_init__(self, dbt_project_path: str | Path | None) -> None: self.project_path = Path(dbt_project_path) if dbt_project_path else None + if not self.dbt_executable_path: + self.dbt_executable_path = get_system_dbt() diff --git a/tests/dbt/test_graph.py b/tests/dbt/test_graph.py index 607e56641e..0ad7424c84 100644 --- a/tests/dbt/test_graph.py +++ b/tests/dbt/test_graph.py @@ -343,7 +343,8 @@ def test_load_via_dbt_ls_without_profile(mock_validate_dbt_command): assert err_info.value.args[0] == expected -def test_load_via_dbt_ls_with_invalid_dbt_path(): +@patch("cosmos.dbt.executable.shutil.which", return_value=None) +def test_load_via_dbt_ls_with_invalid_dbt_path(mock_which): project_config = ProjectConfig(dbt_project_path=DBT_PROJECTS_ROOT_DIR / DBT_PROJECT_NAME) execution_config = ExecutionConfig(dbt_project_path=DBT_PROJECTS_ROOT_DIR / DBT_PROJECT_NAME) render_config = RenderConfig( From 0192d4da4e53d76c4fccdb0f7c63a342d7e641fc Mon Sep 17 00:00:00 2001 From: Justin Bandoro Date: Wed, 15 Nov 2023 16:03:54 -0800 Subject: [PATCH 2/2] change to default factory --- cosmos/config.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cosmos/config.py b/cosmos/config.py index f9d47f5e2e..a33e968304 100644 --- a/cosmos/config.py +++ b/cosmos/config.py @@ -258,7 +258,7 @@ class ExecutionConfig: execution_mode: ExecutionMode = ExecutionMode.LOCAL test_indirect_selection: TestIndirectSelection = TestIndirectSelection.EAGER - dbt_executable_path: str | Path | None = None + dbt_executable_path: str | Path = field(default_factory=get_system_dbt) dbt_project_path: InitVar[str | Path | None] = None @@ -266,5 +266,3 @@ class ExecutionConfig: def __post_init__(self, dbt_project_path: str | Path | None) -> None: self.project_path = Path(dbt_project_path) if dbt_project_path else None - if not self.dbt_executable_path: - self.dbt_executable_path = get_system_dbt()