Skip to content

Remove redundant session.commit() calls in FastAPI route handlers #69492

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:
According to Airflow's coding standards, functions receiving a session parameter should not manually call session.commit(). In the new FastAPI implementation, the database session is injected via the SessionDep dependency. This dependency leverages the create_session context manager, which automatically commits the transaction when the request completes successfully.

Despite this, several route handlers manually call session.commit(), which is redundant and breaks composability.

Steps to reproduce:
Observe explicit session.commit() calls in the following endpoints:

  1. airflow/api_fastapi/execution_api/routes/xcoms.py (in delete_xcom)
  2. airflow/api_fastapi/execution_api/routes/hitl.py
  3. airflow/api_fastapi/core_api/routes/public/hitl.py
  4. airflow/api_fastapi/core_api/routes/public/backfills.py

What you think should happen instead?

The explicit session.commit() calls at the end of these route handlers should be removed, allowing the SessionDep dependency to handle the transaction lifecycle as designed.

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?

Not Applicable

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions