Skip to content
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
17 changes: 2 additions & 15 deletions airflow/providers/microsoft/azure/log/wasb_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from typing import TYPE_CHECKING, Any

from azure.core.exceptions import HttpResponseError
from packaging.version import Version

from airflow.configuration import conf
from airflow.utils.log.file_task_handler import FileTaskHandler
Expand All @@ -36,18 +35,6 @@
from airflow.models.taskinstance import TaskInstance


def get_default_delete_local_copy():
"""Load delete_local_logs conf if Airflow version > 2.6 and return False if not.

TODO: delete this function when min airflow version >= 2.6
"""
from airflow.version import version

if Version(version) < Version("2.6"):
return False
return conf.getboolean("logging", "delete_local_logs")


class WasbTaskHandler(FileTaskHandler, LoggingMixin):
"""
WasbTaskHandler is a python log handler that handles and reads task instance logs.
Expand All @@ -73,8 +60,8 @@ def __init__(
self.log_relative_path = ""
self.closed = False
self.upload_on_close = True
self.delete_local_copy = (
kwargs["delete_local_copy"] if "delete_local_copy" in kwargs else get_default_delete_local_copy()
self.delete_local_copy = kwargs.get(
"delete_local_copy", conf.getboolean("logging", "delete_local_logs")
)

@cached_property
Expand Down
9 changes: 3 additions & 6 deletions tests/providers/microsoft/azure/log/test_wasb_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ def test_write_raises(self):
)

@pytest.mark.parametrize(
"delete_local_copy, expected_existence_of_local_copy, airflow_version",
[(True, False, "2.6.0"), (False, True, "2.6.0"), (True, True, "2.5.0"), (False, True, "2.5.0")],
"delete_local_copy, expected_existence_of_local_copy",
[(True, False), (False, True)],
)
@mock.patch("airflow.providers.microsoft.azure.log.wasb_task_handler.WasbTaskHandler.wasb_write")
def test_close_with_delete_local_logs_conf(
Expand All @@ -190,11 +190,8 @@ def test_close_with_delete_local_logs_conf(
tmp_path_factory,
delete_local_copy,
expected_existence_of_local_copy,
airflow_version,
):
with conf_vars({("logging", "delete_local_logs"): str(delete_local_copy)}), mock.patch(
"airflow.version.version", airflow_version
):
with conf_vars({("logging", "delete_local_logs"): str(delete_local_copy)}):
handler = WasbTaskHandler(
base_log_folder=str(tmp_path_factory.mktemp("local-s3-log-location")),
wasb_log_folder=self.wasb_log_folder,
Expand Down