Skip to content

Bug: Execution API leaks unhandled ValueError as 500 Internal Server Error when DagRun is missing in ti_run route #69392

Description

@KushagraB424

Under which category would you file this issue?

Airflow Core

Apache Airflow version

main

What happened and how to reproduce it?

Issue Description
In the airflow-core package, specifically in airflow-core/src/airflow/api_fastapi/execution_api/routes/task_instances.py inside the ti_run route, a domain-layer exception is currently leaking.

If a DagRun is not found during the ti_run endpoint execution, the code raises a ValueError directly:
raise ValueError(f"DagRun with dag_id={ti.dag_id} and run_id={ti.run_id} not found.")

Because this ValueError is raised inside the route and not caught, it results in an unhandled HTTP 500 Internal Server Error being returned to the client.

Steps to reproduce:
Call the PATCH /execution/task-instances/{task_instance_id}/run endpoint with a valid task_instance_id where the corresponding DagRun does not exist in the database.

What you think should happen instead?

Per the Airflow coding standards, domain-layer exceptions should be translated to an HTTPException at FastAPI route boundaries to avoid leaking internals.

This should be replaced with:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=...)

Operating System

Not Applicable

Deployment

None

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

Not Applicable

Official Helm Chart version

Not Applicable

Kubernetes Version

Not Applicable

Helm Chart configuration

Not Applicable

Docker Image customizations

Not Applicable

Anything else?

already have a fix for this and will be opening a PR shortly!

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:APIAirflow's REST/HTTP APIarea:corekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yet

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions