Skip to content

Commit

Permalink
[Bug] [1.4.0a] Fix #869 - Cosmos does not set dbt project dir to the …
Browse files Browse the repository at this point in the history
…tmp dir (#873)

Fix #869.

Version of dbt I was running is `1.6.4`. It's unclear to me if this is
specific to that version, but I couldn't get the Dbt docs operator to
work without this change. With it, it works, and I do not see any other
issues.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
dwreeves and pre-commit-ci[bot] authored Mar 7, 2024
1 parent 82c8db9 commit b05de60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cosmos/operators/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ def run_command(
env.update(env_vars)

flags = [
"--project-dir",
str(tmp_project_dir),
"--profiles-dir",
str(profile_path.parent),
"--profile",
Expand Down
9 changes: 9 additions & 0 deletions tests/operators/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,18 +703,26 @@ def test_dbt_docs_gcs_local_operator():
@patch("cosmos.config.ProfileConfig.ensure_profile")
@patch("cosmos.operators.local.DbtLocalBaseOperator.run_subprocess")
@patch("cosmos.operators.local.DbtLocalBaseOperator.run_dbt_runner")
@patch("cosmos.operators.local.tempfile.TemporaryDirectory")
@pytest.mark.parametrize("invocation_mode", [InvocationMode.SUBPROCESS, InvocationMode.DBT_RUNNER])
def test_operator_execute_deps_parameters(
mock_temporary_directory,
mock_dbt_runner,
mock_subprocess,
mock_ensure_profile,
mock_exception_handling,
mock_store_compiled_sql,
invocation_mode,
tmp_path,
):
project_dir = tmp_path / "mock_project_tmp_dir"
project_dir.mkdir()

expected_call_kwargs = [
"/usr/local/bin/dbt",
"deps",
"--project-dir",
project_dir.as_posix(),
"--profiles-dir",
"/path/to",
"--profile",
Expand All @@ -732,6 +740,7 @@ def test_operator_execute_deps_parameters(
invocation_mode=invocation_mode,
)
mock_ensure_profile.return_value.__enter__.return_value = (Path("/path/to/profile"), {"ENV_VAR": "value"})
mock_temporary_directory.return_value.__enter__.return_value = project_dir.as_posix()
task.execute(context={"task_instance": MagicMock()})
if invocation_mode == InvocationMode.SUBPROCESS:
assert mock_subprocess.call_args_list[0].kwargs["command"] == expected_call_kwargs
Expand Down

0 comments on commit b05de60

Please sign in to comment.