Skip to content

Conversation

@kaxil
Copy link
Member

@kaxil kaxil commented Oct 23, 2025

When deferrable operators run in the triggerer's async event loop and synchronously access connections (e.g., via @cached_property), the ExecutionAPISecretsBackend failed silently. This occurred because SUPERVISOR_COMMS.send() uses async_to_sync, which raises RuntimeError when called within an existing event loop in a greenback portal context.

Add specific RuntimeError handling in ExecutionAPISecretsBackend that detects this scenario and uses greenback.await_() to call the async versions (aget_connection/aget_variable) as a fallback.

It was originally fixed in #55799 for 3.1.0 but #56602 introduced a bug.

Ideally all providers handle this better and have better written Triggers. Example PR for Databricks: #55568

Fixes #57145


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@kaxil kaxil added this to the Airflow 3.1.1 milestone Oct 23, 2025
@kaxil kaxil force-pushed the fix-conn-async branch 2 times, most recently from 7f160e0 to 42a30d7 Compare October 23, 2025 14:02
When deferrable operators run in the triggerer's async event loop and
synchronously access connections (e.g., via @cached_property), the
`ExecutionAPISecretsBackend` failed silently. This occurred because
`SUPERVISOR_COMMS.send()` uses `async_to_sync`, which raises `RuntimeError`
when called within an existing event loop in a greenback portal context.

Add specific RuntimeError handling in `ExecutionAPISecretsBackend` that
detects this scenario and uses `greenback.await_()` to call the async
versions (aget_connection/aget_variable) as a fallback.

It was originally fixed in apache#55799 for 3.1.0
but apache#56602 introduced a bug.

Ideally all providers handle this better and have better written Triggers. Example
PR for Databricks: apache#55568

Fixes apache#57145
Copy link
Contributor

@amoghrajesh amoghrajesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The job works as I would expect it to now!

If connection exists:

Image

If it doesn't:

Image

For a non databricks deferred job:

    http = HttpOperator(
        task_id="test_HTTP_op",
        http_conn_id="http_default",
        endpoint="get",
        method="GET",
        deferrable=True,
        response_check=lambda response: response.status_code == 200,
        log_response=True,
    )
Image

@kaxil kaxil merged commit da32b68 into apache:main Oct 23, 2025
80 checks passed
@kaxil kaxil deleted the fix-conn-async branch October 23, 2025 15:10
kaxil added a commit that referenced this pull request Oct 23, 2025
When deferrable operators run in the triggerer's async event loop and
synchronously access connections (e.g., via @cached_property), the
`ExecutionAPISecretsBackend` failed silently. This occurred because
`SUPERVISOR_COMMS.send()` uses `async_to_sync`, which raises `RuntimeError`
when called within an existing event loop in a greenback portal context.

Add specific RuntimeError handling in `ExecutionAPISecretsBackend` that
detects this scenario and uses `greenback.await_()` to call the async
versions (aget_connection/aget_variable) as a fallback.

It was originally fixed in #55799 for 3.1.0
but #56602 introduced a bug.

Ideally all providers handle this better and have better written Triggers. Example
PR for Databricks: #55568

Fixes #57145

(cherry picked from commit da32b68)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Connection not available in triggerer

2 participants