From c23debc9244a0ddde33a8cee9fa47c3a39ab7daa Mon Sep 17 00:00:00 2001 From: Kushagra Gupta Date: Tue, 7 Jul 2026 01:14:27 +0530 Subject: [PATCH] Remove redundant session.commit() calls in FastAPI route handlers 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: #69492 --- .../src/airflow/api_fastapi/core_api/routes/public/backfills.py | 1 - .../src/airflow/api_fastapi/core_api/routes/public/hitl.py | 2 -- .../src/airflow/api_fastapi/execution_api/routes/hitl.py | 1 - .../src/airflow/api_fastapi/execution_api/routes/xcoms.py | 1 - 4 files changed, 5 deletions(-) diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/backfills.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/backfills.py index 70c353fb7a22c..dcfba91946533 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/backfills.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/backfills.py @@ -136,7 +136,6 @@ def pause_backfill(backfill_id: NonNegativeInt, session: SessionDep) -> Backfill raise HTTPException(status.HTTP_409_CONFLICT, "Backfill is already completed.") if b.is_paused is False: b.is_paused = True - session.commit() return b diff --git a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py index 2ad11a245d664..ccb2c3dd77f2d 100644 --- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py +++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/hitl.py @@ -243,8 +243,6 @@ def update_hitl_detail( task_instance=locked_ti, session=session, ) - - session.commit() return HITLDetailResponse.model_validate(hitl_detail_model) diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/routes/hitl.py b/airflow-core/src/airflow/api_fastapi/execution_api/routes/hitl.py index 802b09502e09b..74cda44efe74c 100644 --- a/airflow-core/src/airflow/api_fastapi/execution_api/routes/hitl.py +++ b/airflow-core/src/airflow/api_fastapi/execution_api/routes/hitl.py @@ -131,7 +131,6 @@ def update_hitl_detail( hitl_detail_model.chosen_options = payload.chosen_options hitl_detail_model.params_input = payload.params_input session.add(hitl_detail_model) - session.commit() return HITLDetailResponse.from_hitl_detail_orm(hitl_detail_model) diff --git a/airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py b/airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py index 9ab8eb200712a..0cb6ccb23ce54 100644 --- a/airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py +++ b/airflow-core/src/airflow/api_fastapi/execution_api/routes/xcoms.py @@ -481,5 +481,4 @@ def delete_xcom( XComModel.map_index == map_index, ) session.execute(query) - session.commit() return {"message": f"XCom with key: {key} successfully deleted."}