From 3c89c0b85f36981786fbd3a7c67358deeca7ea39 Mon Sep 17 00:00:00 2001 From: Lennart Kloppenburg Date: Fri, 17 Nov 2023 10:43:56 +0100 Subject: [PATCH] Fix rebase conflicts --- cosmos/dbt/graph.py | 7 ++++--- tests/dbt/test_graph.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cosmos/dbt/graph.py b/cosmos/dbt/graph.py index c2551677e..6e4c96ba3 100644 --- a/cosmos/dbt/graph.py +++ b/cosmos/dbt/graph.py @@ -3,6 +3,7 @@ import itertools import json import os +import shutil import tempfile from dataclasses import dataclass, field from pathlib import Path @@ -185,7 +186,7 @@ def load( def run_dbt_ls(self, project_path: Path, tmp_dir: Path, env_vars: dict[str, str]) -> dict[str, DbtNode]: """Runs dbt ls command and returns the parsed nodes.""" - ls_command = [dbt_cmd, "ls", "--output", "json"] + ls_command = [self.dbt_cmd, "ls", "--output", "json"] if self.render_config.exclude: ls_command.extend(["--exclude", *self.render_config.exclude]) @@ -229,8 +230,8 @@ def load_via_dbt_ls(self) -> None: if not self.profile_config: raise CosmosLoadDbtException("Unable to load project via dbt ls without a profile config.") - if not self.profile_config: - raise CosmosLoadDbtException("Unable to load project via dbt ls without a profile config.") + if not shutil.which(self.dbt_cmd): + raise CosmosLoadDbtException(f"Unable to find the dbt executable: {self.dbt_cmd}") with tempfile.TemporaryDirectory() as tmpdir: logger.info( diff --git a/tests/dbt/test_graph.py b/tests/dbt/test_graph.py index de6e97c22..2da989c6c 100644 --- a/tests/dbt/test_graph.py +++ b/tests/dbt/test_graph.py @@ -5,7 +5,7 @@ import pytest -from cosmos.config import ExecutionConfig, ProfileConfig, ProjectConfig, RenderConfig +from cosmos.config import ExecutionConfig, ProfileConfig, ProjectConfig, RenderConfig, CosmosConfigException from cosmos.constants import DbtResourceType, ExecutionMode from cosmos.dbt.graph import ( CosmosLoadDbtException, @@ -349,6 +349,7 @@ def test_load_via_dbt_ls_with_invalid_dbt_path(): render_config = RenderConfig(dbt_project_path=DBT_PROJECTS_ROOT_DIR / DBT_PROJECT_NAME) with patch("pathlib.Path.exists", return_value=True): dbt_graph = DbtGraph( + dbt_cmd="/inexistent/dbt", project=project_config, execution_config=execution_config, render_config=render_config, @@ -358,10 +359,10 @@ def test_load_via_dbt_ls_with_invalid_dbt_path(): profiles_yml_filepath=Path(__file__).parent.parent / "sample/profiles.yml", ), ) - with pytest.raises(CosmosConfigException) as err_info: + with pytest.raises(CosmosLoadDbtException) as err_info: dbt_graph.load_via_dbt_ls() - expected = "Unable to find the dbt executable, attempted: and ." + expected = "Unable to find the dbt executable: /inexistent/dbt" assert err_info.value.args[0] == expected