diff --git a/cosmos/dbt/graph.py b/cosmos/dbt/graph.py index be37ec298..6c207f2ca 100644 --- a/cosmos/dbt/graph.py +++ b/cosmos/dbt/graph.py @@ -133,6 +133,7 @@ def is_freshness_effective(freshness: Optional[dict[str, Any]]) -> bool: def run_command(command: list[str], tmp_dir: Path, env_vars: dict[str, str]) -> str: """Run a command in a subprocess, returning the stdout.""" + command = [str(arg) if arg is not None else "" for arg in command] logger.info("Running command: `%s`", " ".join(command)) logger.debug("Environment variable keys: %s", env_vars.keys()) process = Popen( diff --git a/tests/dbt/test_graph.py b/tests/dbt/test_graph.py index 59d71869d..499cc219c 100644 --- a/tests/dbt/test_graph.py +++ b/tests/dbt/test_graph.py @@ -1121,6 +1121,20 @@ def test_run_command(mock_popen, stdout, returncode): assert return_value == stdout +@patch("cosmos.dbt.graph.Popen") +def test_run_command_none_argument(mock_popen, caplog): + fake_command = ["invalid-cmd", None] + fake_dir = Path("fake_dir") + env_vars = {"fake": "env_var"} + + mock_popen.return_value.communicate.return_value = ("Invalid None argument", None) + with pytest.raises(CosmosLoadDbtException) as exc_info: + run_command(fake_command, fake_dir, env_vars) + + expected = "Unable to run ['invalid-cmd', ''] due to the error:\nInvalid None argument" + assert str(exc_info.value) == expected + + def test_parse_dbt_ls_output_real_life_customer_bug(caplog): dbt_ls_output = """ 11:20:43 Running with dbt=1.7.6