Skip to content

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

Open
KushagraB424 wants to merge 1 commit into
apache:mainfrom
KushagraB424:fix-redundant-session-commit-fastapi
Open

Remove redundant session.commit() calls in FastAPI route handlers#69495
KushagraB424 wants to merge 1 commit into
apache:mainfrom
KushagraB424:fix-redundant-session-commit-fastapi

Conversation

@KushagraB424

Copy link
Copy Markdown

Description

The database session in the FastAPI layer is injected via the SessionDep dependency, which is backed by the create_session context manager. This context manager automatically commits the transaction when a request completes successfully.

Explicitly calling session.commit() inside the route handler is redundant and circumvents the dependency's intended transaction lifecycle management. This brings these specific route handlers in line with the codebase guideline that prohibits functions accepting a session parameter from calling commit.

Impacted Files

  • airflow/api_fastapi/execution_api/routes/xcoms.py
  • airflow/api_fastapi/execution_api/routes/hitl.py
  • airflow/api_fastapi/core_api/routes/public/hitl.py
  • airflow/api_fastapi/core_api/routes/public/backfills.py

Closes: #69492


Was generative AI tooling used to co-author this PR?
  • Yes (Antigravity)

Generated-by: Antigravity following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

The database session in the FastAPI layer is injected via the SessionDep dependency, which automatically commits the transaction when a request completes successfully. Explicitly calling session.commit() inside the route handler is redundant and circumvents the dependency's intended transaction lifecycle management. This brings the route handlers in line with the codebase guideline that prohibits functions accepting a session parameter from calling commit.

Closes: apache#69492
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API area:task-sdk

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant