Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] [1.4.0a] Fix #869 - Cosmos does not set dbt project dir to the tmp dir #873

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading