Skip to content

Conversation

@sjyangkevin
Copy link
Contributor

@sjyangkevin sjyangkevin commented Aug 16, 2025

Close: #52574

As discussed in #52574 , the outlet event extra data is empty because the task runner does not commit the asset changes to the database before calling the callbacks and the listeners. Also, every call to the get_template_context method create and return a new Context object, which might not persist the changes made during the task execution. Therefore, a method to fix this issue is to add a cache to the get_template_context method, ensuring all calls are operating on the same context object.

Since RuntimeTaskInstance is a unhashable type, @functools.cache doesn't work in this case. As an alternative, we probably can convert the context into a property, and the runtime task instance will operate on the property context. However, this implementation breaks the pre-commit hook check-template-context-variable-in-sync.

# Extract keys from the main `context` dictionary assignment
context_assignment = next(
stmt
for stmt in fn_get_template_context.body
if isinstance(stmt, ast.AnnAssign)
and isinstance(stmt.target, ast.Name)
and stmt.target.id == "context"
)

Any feedback regarding how to improve the current implementation for fixing the issue would be appreciated.

manual functional testing

Before making the change, on log line 9, the bottom of the screenshot. The extra field is empty
Screenshot from 2025-08-15 23-15-08

After making the change, on log line 9, the bottom of the screenshot. The extra field contains the asset event extra.
Screenshot from 2025-08-16 00-08-50


^ 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.

@sjyangkevin
Copy link
Contributor Author

sjyangkevin commented Aug 16, 2025

Hi @uranusjr , would you mind have a look whenever you have time? Just want to make sure the fix is on the right direction and would appreciate if you have any feedback. thank you in advance!

@ashb ashb added this to the Airflow 3.0.6 milestone Aug 17, 2025
@kaxil kaxil modified the milestones: Airflow 3.0.6, Airflow 3.0.7 Aug 21, 2025
@sjyangkevin sjyangkevin force-pushed the issues/52574/outlet_event_extra_data_missing branch from 3eaf425 to b6c3ac0 Compare August 23, 2025 05:10
Copy link
Contributor Author

@sjyangkevin sjyangkevin left a comment

Choose a reason for hiding this comment

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

Hi @ashb , I made the updates to the test cases, and also attempted to update the ci pre-commit check logic. Would appreciate if you could have a look at it and feel free to provide further feedback.

@Lee-W Lee-W self-requested a review August 26, 2025 02:50
Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, but would appreciate a second pair of eyes

@sjyangkevin sjyangkevin force-pushed the issues/52574/outlet_event_extra_data_missing branch from 7179e30 to 40c2c91 Compare August 26, 2025 04:04
@Lee-W
Copy link
Member

Lee-W commented Sep 3, 2025

Mostly good, I would appreciate it if we could have someone more familiar with task-sdk to take another look, as this changes the behavior of context, which could have a huge impact.

@amoghrajesh @kaxil @ashb

@dygger
Copy link

dygger commented Sep 12, 2025

Hi @sjyangkevin,

Thanks for your fix — I’ve applied it in my environment and everything is working smoothly now. Really appreciate your effort!

Looking forward to seeing this included in the next Airflow release.

@sjyangkevin
Copy link
Contributor Author

Hi all, I would like to follow up on the PR. I think the major concern here probably is around the impact of the context; recently, I had very limited bandwidth, but will try to get back to this in the upcoming week or two, to further investigate the impact of the change. Thank you for the time to review the PR.

@kaxil kaxil removed this from the Airflow 3.1.1 milestone Oct 20, 2025
@Lee-W Lee-W added the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Oct 22, 2025
@Lee-W Lee-W merged commit 6eb9d9e into apache:main Oct 22, 2025
79 checks passed
github-actions bot pushed a commit that referenced this pull request Oct 22, 2025
…cess Listener (#54568)

(cherry picked from commit 6eb9d9e)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
@github-actions
Copy link

Backport successfully created: v3-1-test

Status Branch Result
v3-1-test PR Link

github-actions bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Oct 22, 2025
…cess Listener (apache#54568)

(cherry picked from commit 6eb9d9e)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
Lee-W pushed a commit that referenced this pull request Oct 22, 2025
…cess Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
@kaxil kaxil added this to the Airflow 3.1.2 milestone Oct 22, 2025
kaxil pushed a commit that referenced this pull request Oct 22, 2025
…cess Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
pierrejeambrun added a commit that referenced this pull request Oct 22, 2025
…57062)

* [v3-1-test] Fix Outlet Event Extra Data is Empty in Task Instance Success Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>

* [v3-1-test] Fix Extra Links translation key. (#57030) (#57040)

(cherry picked from commit 8d71c07)

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>

* [v3-1-test] Fix dags list not rendering (#57037) (#57046)

(cherry picked from commit 8668fe5)

Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>

* [v3-1-test] fix(scheduler): load dag_run eagering for execution API validation (#57010) (#57045)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
fix(scheduler): load dag_run eagering for execution API validation (#56916)" (#56943)

* [v3-1-test] Fix dag list cache invalidation on favouriting a dag (#57039) (#57047)

Fix dag list cache invalidation on favouriting a dag
(cherry picked from commit 4e46212)

Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>

* [v3-1-test] Add new PL translations. (#56359) (#57055)

(cherry picked from commit 6583b6d)

* Add last missing translation for 3.1.1 (#57057)

* [v3-1-test] Close German translation gaps for full UI translation 2025-10-21 (#56980) (#57048)

* [v3-1-test] Fix: Adjust PanelButtons spacing and alignment (#56570)

* fix: adjust PanelButtons spacing and alignment

* Fix PanelButtons layout and button styling

* Fix PanelButtons: use bg.subtle and remove unnecessary _hover
(cherry picked from commit 4c35cd2)

Co-authored-by: anshuksi282-ksolves <anshu.singh@ksolves.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Co-authored-by: anshuksi282-ksolves <anshu.singh@ksolves.com>
@sjyangkevin
Copy link
Contributor Author

Hi @Lee-W , thanks for looking into it , sorry I didn't get the chance yet to make the updates suggested by @uranusjr due to very limited bandwidth in these few weeks;

I am wondering if we still need to make that change, if so, I would like to push that change by around end of the week. thanks!

Let’s add a comment on this attribute to mark this as only implementation detail for caching get_template_context. And/or maybe rename this to _cached_template_context?

kaxil pushed a commit that referenced this pull request Oct 23, 2025
… of sort memory" error (#55589) (#57042)

* [v3-1-test] Fix Outlet Event Extra Data is Empty in Task Instance Success Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>

* [v3-1-test] fix get latest serialized_dag model query to prevent "Out of sort memory" error (#55589)

* fix get latest serialized_dag model query

* fix get latest serialized_dag model query

* add db type check logic
(cherry picked from commit 757db27)

Co-authored-by: Jeongwoo Do <48639483+wjddn279@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
Co-authored-by: Jeongwoo Do <48639483+wjddn279@users.noreply.github.com>
kaxil pushed a commit that referenced this pull request Oct 23, 2025
…cess Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
kaxil pushed a commit that referenced this pull request Oct 23, 2025
…57062)

* [v3-1-test] Fix Outlet Event Extra Data is Empty in Task Instance Success Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>

* [v3-1-test] Fix Extra Links translation key. (#57030) (#57040)

(cherry picked from commit 8d71c07)

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>

* [v3-1-test] Fix dags list not rendering (#57037) (#57046)

(cherry picked from commit 8668fe5)

Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>

* [v3-1-test] fix(scheduler): load dag_run eagering for execution API validation (#57010) (#57045)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
fix(scheduler): load dag_run eagering for execution API validation (#56916)" (#56943)

* [v3-1-test] Fix dag list cache invalidation on favouriting a dag (#57039) (#57047)

Fix dag list cache invalidation on favouriting a dag
(cherry picked from commit 4e46212)

Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>

* [v3-1-test] Add new PL translations. (#56359) (#57055)

(cherry picked from commit 6583b6d)

* Add last missing translation for 3.1.1 (#57057)

* [v3-1-test] Close German translation gaps for full UI translation 2025-10-21 (#56980) (#57048)

* [v3-1-test] Fix: Adjust PanelButtons spacing and alignment (#56570)

* fix: adjust PanelButtons spacing and alignment

* Fix PanelButtons layout and button styling

* Fix PanelButtons: use bg.subtle and remove unnecessary _hover
(cherry picked from commit 4c35cd2)

Co-authored-by: anshuksi282-ksolves <anshu.singh@ksolves.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Co-authored-by: anshuksi282-ksolves <anshu.singh@ksolves.com>
kaxil pushed a commit that referenced this pull request Oct 23, 2025
… of sort memory" error (#55589) (#57042)

* [v3-1-test] Fix Outlet Event Extra Data is Empty in Task Instance Success Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>

* [v3-1-test] fix get latest serialized_dag model query to prevent "Out of sort memory" error (#55589)

* fix get latest serialized_dag model query

* fix get latest serialized_dag model query

* add db type check logic
(cherry picked from commit 757db27)

Co-authored-by: Jeongwoo Do <48639483+wjddn279@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
Co-authored-by: Jeongwoo Do <48639483+wjddn279@users.noreply.github.com>
potiuk added a commit that referenced this pull request Oct 25, 2025
… en (#57060) (#57064)

* [v3-1-test] Fix Outlet Event Extra Data is Empty in Task Instance Success Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>

* [v3-1-test] Fix: Adjust PanelButtons spacing and alignment (#56570) (#57062)

* [v3-1-test] Fix Outlet Event Extra Data is Empty in Task Instance Success Listener (#54568) (#57031)

Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>

* [v3-1-test] Fix Extra Links translation key. (#57030) (#57040)

(cherry picked from commit 8d71c07)

Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>

* [v3-1-test] Fix dags list not rendering (#57037) (#57046)

(cherry picked from commit 8668fe5)

Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>

* [v3-1-test] fix(scheduler): load dag_run eagering for execution API validation (#57010) (#57045)

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
fix(scheduler): load dag_run eagering for execution API validation (#56916)" (#56943)

* [v3-1-test] Fix dag list cache invalidation on favouriting a dag (#57039) (#57047)

Fix dag list cache invalidation on favouriting a dag
(cherry picked from commit 4e46212)

Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>

* [v3-1-test] Add new PL translations. (#56359) (#57055)

(cherry picked from commit 6583b6d)

* Add last missing translation for 3.1.1 (#57057)

* [v3-1-test] Close German translation gaps for full UI translation 2025-10-21 (#56980) (#57048)

* [v3-1-test] Fix: Adjust PanelButtons spacing and alignment (#56570)

* fix: adjust PanelButtons spacing and alignment

* Fix PanelButtons layout and button styling

* Fix PanelButtons: use bg.subtle and remove unnecessary _hover
(cherry picked from commit 4c35cd2)

Co-authored-by: anshuksi282-ksolves <anshu.singh@ksolves.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Co-authored-by: anshuksi282-ksolves <anshu.singh@ksolves.com>

* [v3-1-test] Add possibility of removing extra translations missing in en (#57060)

Sometimes we rename/move translation - we did not have a tool to
remove such dangling translations. Now we have.
(cherry picked from commit 2314099)

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kevin Yang <85313829+sjyangkevin@users.noreply.github.com>
Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
Co-authored-by: Pierre Jeambrun <pierrejbrun@gmail.com>
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Co-authored-by: anshuksi282-ksolves <anshu.singh@ksolves.com>
ashb added a commit to astronomer/airflow that referenced this pull request Nov 5, 2025
As part of the fix in apache#54568 we made `ti.get_runtime_context()` return a
cached context key, which meant that when `run()` in the TaskSDK created a
copy via `task.prepare_for_execution()` the value previously in the context
was the previous copy.

Most of the time this doesn't matter, as the task object that is executed is
the correct value, it's just this is more correct for things like listeners.
ashb added a commit to astronomer/airflow that referenced this pull request Nov 5, 2025
As part of the fix in apache#54568 we made `ti.get_runtime_context()` return a
cached context key, which meant that when `run()` in the TaskSDK created a
copy via `task.prepare_for_execution()` the value previously in the context
was the previous copy.

Most of the time this doesn't matter, as the task object that is executed is
the correct value, it's just this is more correct for things like listeners.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:task-sdk backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Outlet Event Extra Data is Empty in Task Instance Success Listener

7 participants