Coverage for /usr/local/lib/python3.12/site-packages/prefect/server/api/flow_run_states.py: 90%
19 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
1"""
2Routes for interacting with flow run state objects.
3"""
5from typing import List 1a
6from uuid import UUID 1a
8from fastapi import Depends, HTTPException, Path, status 1a
10import prefect.server.models as models 1a
11import prefect.server.schemas as schemas 1a
12from prefect.server.database import PrefectDBInterface, provide_database_interface 1a
13from prefect.server.utilities.server import PrefectRouter 1a
15router: PrefectRouter = PrefectRouter( 1a
16 prefix="/flow_run_states", tags=["Flow Run States"]
17)
20@router.get("/{id:uuid}") 1a
21async def read_flow_run_state( 1a
22 flow_run_state_id: UUID = Path(
23 ..., description="The flow run state id", alias="id"
24 ),
25 db: PrefectDBInterface = Depends(provide_database_interface),
26) -> schemas.states.State:
27 """
28 Get a flow run state by id.
30 For more information, see https://docs.prefect.io/v3/concepts/flows#final-state-determination.
31 """
32 async with db.session_context() as session: 1b
33 flow_run_state = await models.flow_run_states.read_flow_run_state( 1b
34 session=session, flow_run_state_id=flow_run_state_id
35 )
36 if not flow_run_state: 36 ↛ 40line 36 didn't jump to line 40 because the condition on line 36 was always true1b
37 raise HTTPException( 1b
38 status.HTTP_404_NOT_FOUND, detail="Flow run state not found"
39 )
40 return flow_run_state
43@router.get("/") 1a
44async def read_flow_run_states( 1a
45 flow_run_id: UUID,
46 db: PrefectDBInterface = Depends(provide_database_interface),
47) -> List[schemas.states.State]:
48 """
49 Get states associated with a flow run.
50 """
51 async with db.session_context() as session: 1bc
52 return await models.flow_run_states.read_flow_run_states( 1bc
53 session=session, flow_run_id=flow_run_id
54 )