Skip to content

Commit a171a18

Browse files
committed
fix: Don't fail on directory cleanup
1 parent 0153f4a commit a171a18

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

airflow_dbt_python/hooks/dbt.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ def dbt_directory(
293293
store_project_dir = config.project_dir
294294

295295
with update_environment(env_vars):
296-
with TemporaryDirectory(prefix="airflow_tmp") as tmp_dir:
296+
with TemporaryDirectory(
297+
# Cleanup things on a best-effort basis
298+
prefix="airflow_tmp",
299+
ignore_cleanup_errors=True,
300+
) as tmp_dir:
297301
self.log.info("Initializing temporary directory: %s", tmp_dir)
298302

299303
try:
@@ -549,5 +553,5 @@ class DbtSnowflakeHook(DbtHook):
549553
"connect_retries",
550554
"connect_timeout",
551555
"retry_on_database_errors",
552-
"retry_on_database_errors",
556+
"retry_all",
553557
]

tests/hooks/dbt/test_dbt_hook_base.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,22 +89,28 @@ def download_dbt_project(self, *args, **kwargs):
8989

9090

9191
def test_dbt_hook_download_dbt_profiles():
92-
"""Test dbt hook calls remote correctly."""
92+
"""Test dbt hook calls remote correctly.
93+
94+
We ignore types as we are monkey patching a FakeRemote for testing.
95+
"""
9396
hook = DbtHook()
94-
hook.remotes[("", None)] = FakeRemote()
97+
hook.remotes[("", None)] = FakeRemote() # type: ignore
9598

96-
args, kwargs = hook.download_dbt_profiles("/path/to/profiles", "/path/to/store")
99+
args, kwargs = hook.download_dbt_profiles("/path/to/profiles", "/path/to/store") # type: ignore
97100

98101
assert args == ("/path/to/profiles", "/path/to/store")
99102
assert kwargs == {}
100103

101104

102105
def test_dbt_hook_upload_dbt_project():
103-
"""Test dbt hook calls remote correctly."""
106+
"""Test dbt hook calls remote correctly.
107+
108+
We ignore types as we are monkey patching a FakeRemote for testing.
109+
"""
104110
hook = DbtHook()
105-
hook.remotes[("", None)] = FakeRemote()
111+
hook.remotes[("", None)] = FakeRemote() # type: ignore
106112

107-
args, kwargs = hook.upload_dbt_project(
113+
args, kwargs = hook.upload_dbt_project( # type: ignore
108114
"/path/to/profiles", "/path/to/store", replace=True, delete_before=True
109115
)
110116

@@ -115,9 +121,9 @@ def test_dbt_hook_upload_dbt_project():
115121
def test_dbt_hook_download_dbt_project():
116122
"""Test dbt hook calls remote correctly."""
117123
hook = DbtHook(project_conn_id="conn_id")
118-
hook.remotes[("", "conn_id")] = FakeRemote()
124+
hook.remotes[("", "conn_id")] = FakeRemote() # type: ignore
119125

120-
args, kwargs = hook.download_dbt_project("/path/to/profiles", "/path/to/store")
126+
args, kwargs = hook.download_dbt_project("/path/to/profiles", "/path/to/store") # type: ignore
121127

122128
assert args == ("/path/to/profiles", "/path/to/store")
123129
assert kwargs == {}

0 commit comments

Comments
 (0)