Skip to content

Fetching task instances for gantt on dag page without dagrun selected results in 404 #55636

@tirkarthi

Description

@tirkarthi

Apache Airflow version

main (development)

If "Other Airflow 2 version" selected, which one?

No response

What happened?

Whenever a dagrun is not selected then gantt component is not displayed but the query to fetch task instances is still performed with runId as empty string which results in 404 and retries. Previously "~" was passed when there is no runId. When there is no dagrun selected then these queries can be skipped to avoid server load since gantt requires a runId is my assumption. Please correct me if I missed some use case to display gantt across dagruns which I remember was discussed sometime back.

Browser console error message

XHRGET
http://localhost:8000/api/v2/dags/example_hitl_operator/dagRuns//taskInstances
[HTTP/1.1 404 Not Found 3ms]

Relevant code

const { data: taskInstancesData, isLoading: tiLoading } = useTaskInstanceServiceGetTaskInstances(
{
dagId,
dagRunId: runId,
},
undefined,
{
enabled: Boolean(dagId),
refetchInterval: (query) =>
query.state.data?.task_instances.some((ti) => isStatePending(ti.state)) ? refetchInterval : false,
},
);

Something like below could be done

diff --git a/airflow-core/src/airflow/ui/src/layouts/Details/Gantt/Gantt.tsx b/airflow-core/src/airflow/ui/src/layouts/Details/Gantt/Gantt.tsx
index 655e86e19c..7dd8c65b5e 100644
--- a/airflow-core/src/airflow/ui/src/layouts/Details/Gantt/Gantt.tsx
+++ b/airflow-core/src/airflow/ui/src/layouts/Details/Gantt/Gantt.tsx
@@ -114,7 +114,7 @@ export const Gantt = ({ limit }: Props) => {
     },
     undefined,
     {
-      enabled: Boolean(dagId),
+      enabled: Boolean(dagId) && runId !== "",
       refetchInterval: (query) =>
         query.state.data?.task_instances.some((ti) => isStatePending(ti.state)) ? refetchInterval : false,
     },

What you think should happen instead?

No response

How to reproduce

  1. Go to a running dag page. Example http://localhost:8000/dags/example_hitl_operator
  2. Open console panel and see 404 requests with URL where runId is missing. http://localhost:8000/api/v2/dags/example_hitl_operator/dagRuns//taskInstances

Operating System

Ubuntu 20.04

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    AIP-38Modern Web Applicationaffected_version:3.1Issues Reported for 3.1area:UIRelated to UI/UX. For Frontend Developers.area:corekind:bugThis is a clearly a bugpriority:mediumBug that should be fixed before next release but would not block a release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions