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
2 changes: 1 addition & 1 deletion task-sdk/src/airflow/sdk/execution_time/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,10 +1180,10 @@ def _fetch_remote_logging_conn(conn_id: str, client: Client) -> Connection | Non
from airflow.sdk.definitions.connection import Connection

result: Connection | None = Connection(**conn_result.model_dump(exclude={"type"}, by_alias=True))
_REMOTE_LOGGING_CONN_CACHE[conn_id] = result
else:
result = None

_REMOTE_LOGGING_CONN_CACHE[conn_id] = result
return result


Expand Down
32 changes: 32 additions & 0 deletions task-sdk/tests/task_sdk/execution_time/test_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
AssetEventResponse,
AssetProfile,
AssetResponse,
ConnectionResponse,
DagRun,
DagRunState,
DagRunType,
Expand Down Expand Up @@ -3788,6 +3789,37 @@ def noop_request(request: httpx.Request) -> httpx.Response:
assert all(ref() is None for ref in clients), "Client instances should be garbage collected"


def test_fetch_remote_logging_conn_does_not_cache_none_result(mocker):
"""Test that connection caching doesn't cache failed lookups as None."""
conn_id = "test_conn"
client = mocker.Mock()
mocker.patch.object(supervisor, "ensure_secrets_backend_loaded", return_value=[])
mocker.patch.dict(supervisor._REMOTE_LOGGING_CONN_CACHE, {}, clear=True)
client.connections.get.side_effect = [
ErrorResponse(error=ErrorType.PERMISSION_DENIED),
ConnectionResponse(
conn_id=conn_id,
conn_type="example",
host=None,
schema_=None,
login=None,
password=None,
port=None,
extra=None,
),
]

assert supervisor._fetch_remote_logging_conn(conn_id, client) is None
assert conn_id not in supervisor._REMOTE_LOGGING_CONN_CACHE

second_call_result = supervisor._fetch_remote_logging_conn(conn_id, client)
assert second_call_result is not None
assert second_call_result.conn_id == conn_id
assert supervisor._REMOTE_LOGGING_CONN_CACHE[conn_id] is not None
# The first call resulted in None and was not cached, so the second fetch calls the API again.
assert client.connections.get.call_count == 2


def test_process_log_messages_from_subprocess(monkeypatch, caplog):
from airflow.sdk._shared.logging.structlog import PER_LOGGER_LEVELS

Expand Down
Loading