Skip to content
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

Fix duplication of Task tries in the UI (#43891) #43950

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion airflow/api_connexion/endpoints/task_instance_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,12 @@ def _query(orm_object):
)
return query

task_instances = session.scalars(_query(TIH)).all() + session.scalars(_query(TI)).all()
# Exclude TaskInstance with state UP_FOR_RETRY since they have been recorded in TaskInstanceHistory
tis = session.scalars(
_query(TI).where(or_(TI.state != TaskInstanceState.UP_FOR_RETRY, TI.state.is_(None)))
).all()

task_instances = session.scalars(_query(TIH)).all() + tis
return task_instance_history_collection_schema.dump(
TaskInstanceHistoryCollection(task_instances=task_instances, total_entries=len(task_instances))
)
Expand Down
17 changes: 17 additions & 0 deletions tests/api_connexion/endpoints/test_task_instance_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3013,6 +3013,23 @@ def test_should_respond_200(self, session):
assert response.json["total_entries"] == 2 # The task instance and its history
assert len(response.json["task_instances"]) == 2

def test_ti_in_retry_state_not_returned(self, session):
self.create_task_instances(
session=session, task_instances=[{"state": State.SUCCESS}], with_ti_history=True
)
ti = session.query(TaskInstance).one()
ti.state = State.UP_FOR_RETRY
session.merge(ti)
session.commit()

response = self.client.get(
"/api/v1/dags/example_python_operator/dagRuns/TEST_DAG_RUN_ID/taskInstances/print_the_context/tries",
environ_overrides={"REMOTE_USER": "test"},
)
assert response.status_code == 200
assert response.json["total_entries"] == 1
assert len(response.json["task_instances"]) == 1

def test_mapped_task_should_respond_200(self, session):
tis = self.create_task_instances(session, task_instances=[{"state": State.FAILED}])
old_ti = tis[0]
Expand Down