Repository navigation
Add ability to get previous TI on RuntimeTaskInstance - #59712
Conversation
|
@BasPH Do you need more things in previous TI -- like hostname or anything else that doesn't exists in this PR? |
No, looks good! |
gopidesupavan
left a comment
There was a problem hiding this comment.
LGTM, should we add same thing to TriggerRunnerSupervisor?
Add `get_previous_ti()` method to `RuntimeTaskInstance` for retrieving previous task instance executions. Supports filtering by state, logical_date, and run_id. Fixes apache#59609
- Match RuntimeTaskInstanceProtocol signature (AwareDatetime, TaskInstanceState) - Use TaskInstanceState enum in tests - Add GetPreviousTI/PreviousTIResult to triggerer and dag processor exclusion lists
Backport failed to create: v3-1-test. View the failure log Run details
You can attempt to backport this manually by running: cherry_picker a9f3e20 v3-1-testThis should apply the commit to the v3-1-test branch and leave the commit in conflict state marking After you have resolved the conflicts, you can continue the backport process by running: cherry_picker --continue |
|
@kaxil , this failed to backport and looks more like a feature than bug fix. Do we need it in the test branch? |
|
It depends on how you see it. #59609 was raised as a regression over 2.x so hurts migration path from Airflow 2 to 3.
@BasPH since you created that issue, could you wait for 3.2 -- around March/April ? |
Add `get_previous_ti()` method to `RuntimeTaskInstance` for retrieving previous task instance executions. Supports filtering by state, logical_date, and run_id. Fixes apache#59609 - Match RuntimeTaskInstanceProtocol signature (AwareDatetime, TaskInstanceState) - Use TaskInstanceState enum in tests - Add GetPreviousTI/PreviousTIResult to triggerer and dag processor exclusion lists
|
Hello and thank you for adding back this feature ! Do you confirm it is still on the 3.2 roadmap, and that its release is still planned around March/April ? Looking forward to it to finalize the migration. |
Hey, yes it will be part of Airflow 3.2 -- planned to be released end of May-early April |
Two more callers of ``session.scalars(...).first()`` / ``session.execute(select(...)).first()`` were still missing an explicit ``.limit(1)``. Because SQLAlchemy 2.0's ``Result.first()`` does not add one (unlike the legacy ``Query.first``), each call sends every matching row to the Python process and discards all but the first. The favorite existence check is bounded to a single row per (dag_id, user_id) by the schema, but the previous-TI lookup scans every earlier matching TI. Introduced independently of apache#52325's migration: get_previous_task_instance came in apache#59712, unfavorite_dag's existence probe in apache#51264. Same anti-pattern as the four sites apache#72554 fixes; the tests reuse the ``capture_orm_selects`` helper that PR introduces.
* Bound remaining single-row lookups with .limit(1) Two more callers of ``session.scalars(...).first()`` / ``session.execute(select(...)).first()`` were still missing an explicit ``.limit(1)``. Because SQLAlchemy 2.0's ``Result.first()`` does not add one (unlike the legacy ``Query.first``), each call sends every matching row to the Python process and discards all but the first. The favorite existence check is bounded to a single row per (dag_id, user_id) by the schema, but the previous-TI lookup scans every earlier matching TI. Introduced independently of #52325's migration: get_previous_task_instance came in #59712, unfavorite_dag's existence probe in #51264. Same anti-pattern as the four sites #72554 fixes; the tests reuse the ``capture_orm_selects`` helper that PR introduces. * Also assert the returned row on the previous-TI regression test
* Bound remaining single-row lookups with .limit(1) Two more callers of ``session.scalars(...).first()`` / ``session.execute(select(...)).first()`` were still missing an explicit ``.limit(1)``. Because SQLAlchemy 2.0's ``Result.first()`` does not add one (unlike the legacy ``Query.first``), each call sends every matching row to the Python process and discards all but the first. The favorite existence check is bounded to a single row per (dag_id, user_id) by the schema, but the previous-TI lookup scans every earlier matching TI. Introduced independently of #52325's migration: get_previous_task_instance came in #59712, unfavorite_dag's existence probe in #51264. Same anti-pattern as the four sites #72554 fixes; the tests reuse the ``capture_orm_selects`` helper that PR introduces. * Also assert the returned row on the previous-TI regression test (cherry picked from commit ff83957) Co-authored-by: Pierre Jeambrun <[email protected]>
Fixes #59609
Add
get_previous_ti()method toRuntimeTaskInstancefor retrieving previous task instance executions. Supports filtering by state, logical_date, and run_id.This will help users migrating from Airflow 2.x since they were able to do
prev_ti = ti.get_previous_ti(state='success')in Airflow 2 as described in the GitHub issue.^ 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.