-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Use SDK serde for trigger and next kwargs serialization #59711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
amoghrajesh
merged 38 commits into
apache:main
from
astronomer:use-serde-for-next-kwargs
Dec 30, 2025
Merged
Use SDK serde for trigger and next kwargs serialization #59711
amoghrajesh
merged 38 commits into
apache:main
from
astronomer:use-serde-for-next-kwargs
Dec 30, 2025
Conversation
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
uranusjr
reviewed
Dec 23, 2025
airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py
Show resolved
Hide resolved
amoghrajesh
commented
Dec 29, 2025
uranusjr
reviewed
Dec 29, 2025
airflow-core/tests/unit/api_fastapi/execution_api/versions/head/test_task_instances.py
Outdated
Show resolved
Hide resolved
uranusjr
reviewed
Dec 29, 2025
Lee-W
approved these changes
Dec 29, 2025
Contributor
Author
|
Ok, finally a green build! |
kaxil
approved these changes
Dec 29, 2025
Member
kaxil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One comment about the upgrade path when there are some triggers already deffered which is worth verifying, rest lgtm.
Subham-KRLX
pushed a commit
to Subham-KRLX/airflow
that referenced
this pull request
Jan 2, 2026
stegololz
pushed a commit
to stegololz/airflow
that referenced
this pull request
Jan 9, 2026
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.
Related PR: #47061
In this PR I intend to migrate / swap the serialization of deferred task data (
trigger_kwargsandnext_kwargs) fromBaseSerialization.serializeto instead use the serde library which is already in task sdk: #58992Why do it?
BaseSerializationcreates tight coupling between task-sdk and airflow-coreBaseSerialisationChanges of note / Considerations while making this change
When a task defers, Airflow saves:
Previously, both used BaseSerialization to store data in the DB.
This is how the current flow looks like:
Forward flow (defer):
Return flow (resume):
Target flow with this change:
Forward flow (defer):
Return flow (resume):
You can also see above that the API server was doing unnecessary work. When a worker sent deferred task data to the API server, the data arrived in serialized format. The API server would:
Changes
The worker now serializes data with
serdebefore sending it anywhere. The API server receives this serde serialised data and stores it directly without any processing. It's truly a proxy now - no deserializing, no re-serializing, just storing as-is.Due to above,
ExtendedJSON(which auto-serializes) is swapped with plain JSON/JSONB columns. This removes the automatic serialization at the database layer.When a task resumes, it gets data as stored it the database and it explicitly
deserializesthe data back to original types.Key design principle: Serialization/Deserialization is the worker's responsibility (very similar to xcoms), not the API server's or the database's. The worker knows what types it's working with and when it needs them converted.
Testing
Example with types now
Let's assume that this is the
next_kwargspassed around (trigger_kwargs will be similar){ "location": ("New York", "USA"), "timestamp": pendulum.datetime(2024, 1, 15, 10, 30, 0, tz="UTC") }Earlier storage format:
Now:
This data would then be deserialized by
BaseSerializationearlier and now byserdeEarlier:
Observe no type loss in both cases.
Compat testing
What we really care about most is backcompat. That means server upgraded but worker hasn't / isn't ready yet.
Situation 1
To verify that existing deferred tasks can resume after upgrading to the new serde serialization format, I ran this test:
Once in deferred, recorded its details such as:
Trigger table:
Task Instance Table:
{"__var": {"message": "hello from deferred task", "numbers": [1, 2, 3, 4, 5], "timestamp": {"__var": 1766486739.627232, "__type": "datetime"}, "numbers_in_tuple": {"__var": [6, 7, 8, 9, 10], "__type": "tuple"}}, "__type": "dict"}Logs when it runs fine on main look like:
Changed from main branch to my branch by shutting breeze off and starting without db reset on my branch
Went back to airflow UI to check if anything crashes
When the datetime trigger fired, the deferred task resumed fine
The worker's deser logic fell back to the BaseSerialization format and successfully deserialized and passed next_kwargs to execute_complete() and due to that the task completed successfully with all data intact.
Ran purely on new branch:
Situation 2
As mentioned by @kaxil, we also need to test and certify the scenario where the server is new but worker is still old, ie. it still sends BaseSerialisation kwargs instead of using serde.
To test this, using the same dag as above, I undid all the changes to task sdk
Once this was done, I am certain that the data that will be sent to the API server will now be BaseSerialisation encoded.
Ran the DAG
Checked the database:
Trigger table:
{"__var": {"moment": {"__var": 1766584500.193306, "__type": "datetime"}, "end_from_trigger": false}, "__type": "dict"}next_kwargs in TI table:
{"__var": {"message": "hello from deferred task", "numbers": [1, 2, 3, 4, 5], "timestamp": {"__var": 1766584440.2096, "__type": "datetime"}, "numbers_in_tuple": {"__var": [6, 7, 8, 9, 10], "__type": "tuple"}}, "__type": "dict"}Whats pending
^ 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.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.