Skip to content

Commit

Permalink
Add logging of stdout to dbt graph run_command. (#1390)
Browse files Browse the repository at this point in the history
Currently run_command functions put only stderr or stdout into logger.
Which is misleading, because there are also important information in
stdout even if something exists in stderr.

## Related Issue(s)

closes #1356
  • Loading branch information
KarolGongola authored Dec 19, 2024
1 parent 22b20f1 commit 0e826b1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cosmos/dbt/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def run_command(command: list[str], tmp_dir: Path, env_vars: dict[str, str]) ->
)

if returncode or "Error" in stdout.replace("WarnErrorOptions", ""):
details = stderr or stdout
details = f"stderr: {stderr}\nstdout: {stdout}"
raise CosmosLoadDbtException(f"Unable to run {command} due to the error:\n{details}")

return stdout
Expand Down
6 changes: 3 additions & 3 deletions tests/dbt/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def test_load_via_dbt_ls_with_non_zero_returncode(mock_popen, postgres_profile_c
execution_config=execution_config,
profile_config=postgres_profile_config,
)
expected = r"Unable to run \['.+dbt', 'deps', .*\] due to the error:\nSome stderr message"
expected = r"Unable to run \['.+dbt', 'deps', .*\] due to the error:\nstderr: Some stderr message\nstdout: "
with pytest.raises(CosmosLoadDbtException, match=expected):
dbt_graph.load_via_dbt_ls()

Expand All @@ -859,7 +859,7 @@ def test_load_via_dbt_ls_with_runtime_error_in_stdout(mock_popen_communicate, po
execution_config=execution_config,
profile_config=postgres_profile_config,
)
expected = r"Unable to run \['.+dbt', 'deps', .*\] due to the error:\nSome Runtime Error"
expected = r"Unable to run \['.+dbt', 'deps', .*\] due to the error:\nstderr: \nstdout: Some Runtime Error"
with pytest.raises(CosmosLoadDbtException, match=expected):
dbt_graph.load_via_dbt_ls()

Expand Down Expand Up @@ -1131,7 +1131,7 @@ def test_run_command_none_argument(mock_popen, caplog):
with pytest.raises(CosmosLoadDbtException) as exc_info:
run_command(fake_command, fake_dir, env_vars)

expected = "Unable to run ['invalid-cmd', '<None>'] due to the error:\nInvalid None argument"
expected = "Unable to run ['invalid-cmd', '<None>'] due to the error:\nstderr: None\nstdout: Invalid None argument"
assert str(exc_info.value) == expected


Expand Down

0 comments on commit 0e826b1

Please sign in to comment.