Skip to content

Commit c792b25

Browse files
authored
Restore function scoped httpx import in file_task_handler for perf (#36753)
1 parent fd68f05 commit c792b25

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

airflow/utils/log/file_task_handler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from typing import TYPE_CHECKING, Any, Callable, Iterable
3030
from urllib.parse import urljoin
3131

32-
import httpx
3332
import pendulum
3433

3534
from airflow.configuration import conf
@@ -79,6 +78,9 @@ def _set_task_deferred_context_var():
7978

8079

8180
def _fetch_logs_from_service(url, log_relative_path):
81+
# Import occurs in function scope for perf. Ref: https://github.com/apache/airflow/pull/21438
82+
import httpx
83+
8284
from airflow.utils.jwt_signer import JWTSigner
8385

8486
timeout = conf.getint("webserver", "log_fetch_timeout_sec", fallback=None)
@@ -557,7 +559,9 @@ def _read_from_logs_server(self, ti, worker_log_rel_path) -> tuple[list[str], li
557559
messages.append(f"Found logs served from host {url}")
558560
logs.append(response.text)
559561
except Exception as e:
560-
if isinstance(e, httpx.UnsupportedProtocol) and ti.task.inherits_from_empty_operator is True:
562+
from httpx import UnsupportedProtocol
563+
564+
if isinstance(e, UnsupportedProtocol) and ti.task.inherits_from_empty_operator is True:
561565
messages.append(self.inherits_from_empty_operator_log_message)
562566
else:
563567
messages.append(f"Could not read served logs: {e}")

0 commit comments

Comments
 (0)