palakbhati opened a new pull request, #77145:
URL: https://github.com/apache/airflow/pull/77145
closes: #77137
### Problem
Calling `PythonOperator.execute(context={})` loses `op_kwargs` on Airflow
3.x, so the
callable is invoked without its arguments and raises `TypeError`. This
breaks the
custom operator testing pattern from the best practices docs. It works on
2.11.
### Root cause
`context_merge` in `task-sdk/src/airflow/sdk/definitions/context.py` starts
with:
if not context:
context = Context()
An empty dict is falsy, so this rebinds the local name to a new `Context`
and the
update goes there. The caller's dict is never modified.
`PythonOperator.execute` then
calls `determine_kwargs(context)` on the caller's dict, which is still
empty, so
`op_kwargs` ends up empty.
The check was added in #42808 (SLA purge follow-up) without a stated reason
and moved
unchanged into the Task SDK in #53600. No caller passes `None`, and the
parameter is
typed `Context`, so I removed the check instead of replacing it with a None
guard.
### Impact
All callers of `context_merge` follow the same pattern (merge, then read the
caller's
dict), so they all had this bug with an empty context and are all fixed by
this one
change: the standard provider's PythonOperator (sync and async),
PythonSensor and
`@task.bash`, plus decorators in cncf.kubernetes, common.sql and common.ai.
It also fixes `BaseNotifier.__await__`: a notifier created without a context
passed
`{}` to `async_notify`, without its template fields.
### Tests
- task-sdk: `test_context_merge_updates_empty_dict_in_place`
- task-sdk: `test_notifier_await_without_context_passes_template_fields`
- providers/standard: `test_execute_with_empty_context_passes_op_kwargs`,
parametrized
with a sync and an async callable, running in both `TestPythonOperator` and
`TestPythonAsyncOperator`
All of them fail without the fix (the provider test fails with the same
`TypeError`
as the issue) and pass with it.
### Questions for reviewers
1. The provider test is gated on `AIRFLOW_V_3_4_PLUS` so it skips in
compatibility
runs against released 3.x versions that still have the bug. 3.4.0rc2
still has the
bug, so the gate is only correct if this fix is backported to `v3-4-test`
before
3.4.0 final. Should it be backported, or would you prefer a different
gate?
2. No newsfragment, since this is an ordinary bug fix that restores the 2.x
behavior.
Happy to add one if you think it's needed.
#### Was generative AI tooling used to co-author this PR?
- [x] Yes (please specify the tool below)
Generated-by: Claude Code (Opus 5.5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]