Repository navigation
Fix context_merge discarding empty dictionary context - #77171
Open
pranjal9091 wants to merge 1 commit into
Open
pranjal9091 wants to merge 1 commit into
pranjal9091 wants to merge 1 commit into
Conversation
When passing an empty mapping (such as `{}` during unit testing of
custom operators with `operator.execute(context={})`), `context_merge`
evaluated `if not context: context = Context()`. Because `{}` is falsy,
this rebound the local `context` parameter to a newly created `Context()`
instance instead of mutating the passed dictionary in-place. As a result,
`op_kwargs` merged into context were discarded from the caller's perspective,
causing operators like `PythonOperator` to drop their callable keyword arguments.
This removes the local re-assignment so `context.update(*args, **kwargs)`
always updates the caller's mapping in-place.
pranjal9091
force-pushed
the
fix/context-merge-empty-dict
branch
from
November 17, 2026 03:50
ccaf239 to
b0745a9
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes: #77137
Description
In
airflow.sdk.definitions.context.context_merge:When callers pass an empty dictionary (such as
context={}in unit tests following the standard operator testing patternoperator.execute(context={})),if not context:evaluates toTrue. Because Python passes arguments by reference, re-assigning the local variablecontext = Context()rebinds only the local reference in the function scope rather than mutating the caller's mapping in-place.In
PythonOperator.execute:Because caller's
contextremained{}:determine_kwargs(context)found none of the callable's arguments incontextand resetself.op_kwargs = {}.TypeError: ... missing required positional argument.This removes the local reassignment in
context_mergesocontext.update(*args, **kwargs)directly updates any mapping (including empty dicts) in-place.Testing
task-sdk/tests/task_sdk/definitions/test_context.pycoveringcontext_mergewith empty dicts, kwargs, existing dictionaries, and iterable key-value pairs.