fix: API Server - Return 404 from /api/executions/{id}/state when execution does not exist - #356
Open
AryanKansagara wants to merge 1 commit into
Open
AryanKansagara wants to merge 1 commit into
AryanKansagara wants to merge 1 commit into
Conversation
…cution does not exist
get_graph_execution_state built its response purely by counting child
execution nodes, so an unknown execution id produced an empty count and
was reported as HTTP 200 with has_ended=True. Callers could not tell a
finished graph from a missing one.
Check that the ExecutionNode exists before counting and raise
ItemNotFoundError otherwise, matching get_container_execution_state.
The router already maps ItemNotFoundError to a 404 response, so both
/api/executions/{id}/state and /api/executions/{id}/graph_execution_state
now return 404 for unknown ids.
Closes TangleML#49
Signed-off-by: Aryan Kansagara <aryankk07@gmail.com>
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.
Closes #49
Problem
GET /api/executions/{id}/state(and its alias/api/executions/{id}/graph_execution_state) returns HTTP 200 for an execution id that does not exist in the database. The body looks like a finished, empty graph:Clients polling this endpoint cannot distinguish "the graph finished" from "this id does not exist". Every other lookup-by-id endpoint in
api_server_sql.py, including the neighbouring/api/executions/{id}/container_state, returns 404 in this situation.Cause
ExecutionNodesApiService_Sql.get_graph_execution_statebuilds its response by counting childExecutionNoderows grouped by status. It never checks that the parent execution exists. For an unknown id the counts are simply zero, and zero ended out of zero total is reported ashas_ended=True.Fix
Add the same existence check that
get_container_execution_statealready performs, before any counting:api_router.pyalready mapsItemNotFoundErrorto a 404 JSON response, so no router changes are needed. The error message matches the sibling endpoint. Behaviour for existing ids is unchanged; a real graph node with no children still returns 200 with empty stats (covered by the existingtest_no_children_returns_empty_stats).Tests
TestGetGraphExecutionState.test_missing_execution_raises_not_foundintests/test_execution_nodes_api_service.py, mirroring the existingtest_missing_execution_still_raises_not_foundfor the container state endpoint.Verification over HTTP
Against an empty SQLite database, before the change:
After the change:
Things to be aware of
get_container_execution_statealready pays the same cost on every call.