Skip to content

Validate CallbackTrigger callback path before running the callback - #74842

Open
potiuk wants to merge 2 commits into
apache:mainfrom
potiuk:validate-callback-trigger-path
Open

potiuk wants to merge 2 commits into
apache:mainfrom
potiuk:validate-callback-trigger-path

Conversation

@potiuk

@potiuk potiuk commented Oct 16, 2026

Copy link
Copy Markdown
Member

Follow-up to #69792, which made the Triggerer check that a deferring task's trigger classpath resolves to a BaseTrigger subclass before using it.

CallbackTrigger resolves its callback_path with import_string and calls the result without checking what it is. This PR checks the callback path the same way trigger classpaths are checked. Before the callback runs, the resolved object must be one of:

  • a coroutine function (async def),
  • an awaitable callable, such as an async BaseNotifier subclass (has __await__),
  • a callable object whose __call__ is async def.

The first two are what AsyncCallback.verify_callable already requires when a deadline callback is defined. Triggerer callbacks are always awaited, so every documented use is still accepted. Modules, non-callable attributes, plain classes and sync functions now fail the callback with a clear InvalidCallbackPathError and are not called. Before this change, a sync function was called and only then failed with a "not awaitable" error. Like any other callback failure, the error is reported as a FAILED callback event and the Triggerer keeps running.

Tests added:

  • unit tests for _validate_callback, one case each for accepted and rejected targets,
  • a CallbackTrigger.run test that resolves a real coroutine-function path,
  • a CallbackTrigger.run test that checks invalid paths (module, non-callable attribute, sync callable, plain class) fail without the target being called.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Claude Opus 5 following the guidelines

The callback path resolved by CallbackTrigger must now be a coroutine
function or an awaitable callable (such as an async notifier class),
matching what AsyncCallback accepts. Anything else fails the callback
before it is called, the same way trigger classpaths are validated.

Generated-by: Claude Opus 5 following the guidelines at https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions
@potiuk potiuk added this to the Airflow 3.4.0 milestone Oct 16, 2026
@potiuk potiuk added the backport-to-v3-4-test Backport to v3-4-test label Oct 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v3-4-test Backport to v3-4-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant