Return 404 instead of 500 when workflow not found (#SKY-7256) (#4699)

This commit is contained in:
Celal Zamanoglu
2026-02-11 16:31:38 +03:00
committed by GitHub
parent 5e9c1f4f68
commit cc84c927f2
2 changed files with 42 additions and 25 deletions

View File

@@ -1580,34 +1580,44 @@ async def run_block(
# LOG.critical("REMOVING BROWSER SESSION ID")
# block_run_request.browser_session_id = None
await block_service.validate_block_labels(
workflow_permanent_id=block_run_request.workflow_id,
organization_id=organization.organization_id,
block_labels=block_run_request.block_labels,
)
try:
await block_service.validate_block_labels(
workflow_permanent_id=block_run_request.workflow_id,
organization_id=organization.organization_id,
block_labels=block_run_request.block_labels,
)
workflow_run = await block_service.ensure_workflow_run(
organization=organization,
template=template,
workflow_permanent_id=block_run_request.workflow_id,
block_run_request=block_run_request,
)
workflow_run = await block_service.ensure_workflow_run(
organization=organization,
template=template,
workflow_permanent_id=block_run_request.workflow_id,
block_run_request=block_run_request,
)
browser_session_id = block_run_request.browser_session_id
browser_session_id = block_run_request.browser_session_id
await block_service.execute_blocks(
request=request,
background_tasks=background_tasks,
api_key=x_api_key or "",
block_labels=block_run_request.block_labels,
workflow_id=block_run_request.workflow_id,
workflow_run_id=workflow_run.workflow_run_id,
workflow_permanent_id=workflow_run.workflow_permanent_id,
organization=organization,
user_id=user_id,
browser_session_id=browser_session_id,
block_outputs=block_run_request.block_outputs,
)
await block_service.execute_blocks(
request=request,
background_tasks=background_tasks,
api_key=x_api_key or "",
block_labels=block_run_request.block_labels,
workflow_id=block_run_request.workflow_id,
workflow_run_id=workflow_run.workflow_run_id,
workflow_permanent_id=workflow_run.workflow_permanent_id,
organization=organization,
user_id=user_id,
browser_session_id=browser_session_id,
block_outputs=block_run_request.block_outputs,
)
except SkyvernHTTPException:
raise
except Exception:
LOG.exception(
"Unexpected error running blocks",
workflow_id=block_run_request.workflow_id,
organization_id=organization.organization_id,
)
raise
return BlockRunResponse(
block_labels=block_run_request.block_labels,

View File

@@ -41,6 +41,7 @@ from skyvern.exceptions import (
MissingValueForParameter,
ScriptTerminationException,
SkyvernException,
SkyvernHTTPException,
WorkflowNotFound,
WorkflowNotFoundForWorkflowRun,
WorkflowRunNotFound,
@@ -3432,6 +3433,12 @@ class WorkflowService:
)
return updated_workflow
except SkyvernHTTPException:
# Bubble up well-formed client errors (e.g. WorkflowNotFound 404)
# so they are not wrapped in a 500 by the caller.
if new_workflow_id:
await self.delete_workflow_by_id(workflow_id=new_workflow_id, organization_id=organization_id)
raise
except Exception as e:
if new_workflow_id:
LOG.error(