From f37009c487452749cefa2d11052e9e4c5610f5d9 Mon Sep 17 00:00:00 2001 From: Aman Sachan Date: Sun, 31 May 2026 00:36:00 +0000 Subject: [PATCH] fix: handle empty dict handler response without KeyError When a handler returns an empty dict {}, rp_job.py removes the 'output' key before returning. In _sim_runsync and _sim_status, the code unconditionally accessed job_output['output'], causing a KeyError. Changed both locations to use job_output.get('output') instead, which gracefully returns None when the key is absent. This matches the documented behavior where returning {} from a handler is valid. Fixes #459 --- runpod/serverless/modules/rp_fastapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runpod/serverless/modules/rp_fastapi.py b/runpod/serverless/modules/rp_fastapi.py index f4aff225..b7458af7 100644 --- a/runpod/serverless/modules/rp_fastapi.py +++ b/runpod/serverless/modules/rp_fastapi.py @@ -339,7 +339,7 @@ async def _sim_runsync(self, job_request: DefaultRequest) -> JobOutput: thread.start() return jsonable_encoder( - {"id": job.id, "status": "COMPLETED", "output": job_output["output"]} + {"id": job.id, "status": "COMPLETED", "output": job_output.get("output")} ) # ---------------------------------- stream ---------------------------------- # @@ -416,5 +416,5 @@ async def _sim_status(self, job_id: str) -> JobOutput: thread.start() return jsonable_encoder( - {"id": job_id, "status": "COMPLETED", "output": job_output["output"]} + {"id": job.id, "status": "COMPLETED", "output": job_output.get("output")} )