Use FastAPI exception handler for execution API database errors#67206
Open
ColtenOuO wants to merge 1 commit into
Open
Use FastAPI exception handler for execution API database errors#67206ColtenOuO wants to merge 1 commit into
ColtenOuO wants to merge 1 commit into
Conversation
Contributor
SameerMesiah97
left a comment
There was a problem hiding this comment.
This looks reasonable to me overall. Main thing I think is missing is a regression test exercising a real execution API route with a mocked SQLAlchemyError, mainly to verify the FastAPI handler registration and response contract end-to-end. CI needs to complete running too but I still think the above point applies regardless of that.
5051c06 to
11c5554
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The execution API had two routes (
ti_run,ti_update_state) wrapping theirsession.executecalls intry/except SQLAlchemyErrorand converting toHTTPException(500, "Database error occurred"). The TODO inroutes/task_instances.pyflagged this for replacement with FastAPI's custom exception handlers.This adds
@app.exception_handler(SQLAlchemyError)alongside the existing catch-all inexecution_api/app.py. The new handler logs the request path/method and returns{"detail": "Database error occurred"}with status 500 — the same shape the routes produced before. The per-routetry/exceptblocks are removed and bodies dedented (which accounts for most of the line churn).Scope note
The TODO was only on
ti_update_state(around the call tosession.execute(query)that writes the new state + auditLog). However,ti_runhad the sametry/except SQLAlchemyErrorboilerplate without a TODO, doing literally the same translation. Once the global handler exists, both local catches become redundant, so this PR removes both for consistency rather than leaving the codebase in a half-migrated state.If reviewers prefer a strict TODO-only scope, I'm happy to revert the
ti_runchange and open a separate cleanup PR for it.Was generative AI tooling used to co-author this PR?