Skip to content

Commit

Permalink
Check for agent existence before updating flow run agent
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmeek committed Oct 23, 2020
1 parent c821f35 commit 3f3ad8f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/prefect_server/api/runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ async def delete_flow_run(flow_run_id: str) -> bool:


@register_api("runs.update_flow_run_agent")
async def update_flow_run_agent(flow_run_id: str, agent_id: str) -> None:
async def update_flow_run_agent(flow_run_id: str, agent_id: str) -> bool:
"""
Updates the agent instance of a flow run
Expand All @@ -406,6 +406,11 @@ async def update_flow_run_agent(flow_run_id: str, agent_id: str) -> None:
Returns:
bool: if the update was successful
"""

agent = await models.Agent.where(id=agent_id).first()
if not agent:
return False

result = await models.FlowRun.where(id=flow_run_id).update(
set={"agent_id": agent_id}
)
Expand Down

0 comments on commit 3f3ad8f

Please sign in to comment.