dabla opened a new pull request, #74766:
URL: https://github.com/apache/airflow/pull/74766

   #74147 added `get_async_extra_dejson()` so async hooks can read a 
connection's extra without the synchronous secret masking of `extra_dejson`. 
That masking sends `MaskSecret` to the supervisor and raises 
`DeadlockImminentError` when another async call is in flight on the same event 
loop. On Airflow 3.3.2+ the helper awaits `Connection.aextra_dejson()`. On 
older versions it reads `extra_dejson` in a worker thread, where blocking on 
the supervisor is safe.
   
   That covers the extra, but not fetching the connection. 
`get_async_connection()` awaits the hook's `aget_connection()` whenever the 
hook has one, which is the case from Airflow 3.1. Before 3.3.2, Airflow core 
masks secrets synchronously on that path:
   
   - 3.1 and 3.2: `_async_get_connection` calls `_mask_connection_secrets`, 
which calls the sync `mask_secret` 
([3.2.0](https://github.com/apache/airflow/blob/3.2.0/task-sdk/src/airflow/sdk/execution_time/context.py#L191)).
   - 3.3.0 and 3.3.1: the secrets-backend branch calls `conn.get_uri()`, which 
reads `extra_dejson` 
([3.3.1](https://github.com/apache/airflow/blob/3.3.1/task-sdk/src/airflow/sdk/execution_time/context.py#L271)).
 3.3.2 switched it to `aget_uri()`.
   
   So an async hook using `get_async_connection()` + 
`get_async_extra_dejson()`, such as the async `OpenAIHook.aget_conn()` in 
#74149, can still hit `DeadlockImminentError` on 3.1 to 3.3.1, before it ever 
reads the extra.
   
   On those versions, `get_async_connection()` now runs the sync 
`get_connection()` in a worker thread, the same fallback 
`get_async_extra_dejson()` uses for `extra_dejson`. The version marker is also 
the same: `Connection.aextra_dejson` exists from 3.3.2. A hook that overrides 
`aget_connection()` is still awaited, so subclass overrides keep working on 
every version. Only the base `BaseHook.aget_connection()` gives way to 
`get_connection()`. On 3.3.2+ and on Airflow 2 nothing changes.
   
   Tests: two new tests in `test_connection.py`, run with the SDK `Connection` 
replaced by one without `aextra_dejson`:
   - a hook class or instance that only has the base `aget_connection()` gets 
its connection from `get_connection()` on a worker thread;
   - a hook that overrides `aget_connection()` still gets its connection from 
that override.
   
   Both fail without the change. The existing tests pass unchanged.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes — Claude Opus 5.5
   
   Generated-by: Claude Opus 5.5 following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to