Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion runpod/serverless/modules/rp_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ async def run_job(handler: Callable, job: Dict[str, Any]) -> Dict[str, Any]:
)

log.debug(f"Handler output: {job_output}", job["id"])
empty_handler_output = isinstance(job_output, dict) and not job_output

if isinstance(job_output, dict):
error_msg = job_output.pop("error", None)
Expand All @@ -281,7 +282,7 @@ async def run_job(handler: Callable, job: Dict[str, Any]) -> Dict[str, Any]:
else:
run_result = {"output": job_output}

if run_result.get("output") == {}:
if run_result.get("output") == {} and not empty_handler_output:
run_result.pop("output")

check_return_size(run_result) # Checks the size of the return body.
Expand Down
21 changes: 21 additions & 0 deletions tests/test_serverless/test_modules/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ def test_runsync(self):
"output": {"result": "success"},
}

empty_handler = Mock(return_value={})
empty_worker_api = rp_fastapi.WorkerAPI({"handler": empty_handler})
empty_runsync_return = asyncio.run(
empty_worker_api._sim_runsync(default_input_object)
)
assert empty_runsync_return == {
"id": "test-123",
"status": "COMPLETED",
"output": {},
}

# Test with generator handler
def generator_handler(job):
del job
Expand Down Expand Up @@ -330,6 +341,16 @@ def test_status(self):
"output": {"result": "success"},
}

empty_handler = Mock(return_value={})
empty_worker_api = rp_fastapi.WorkerAPI({"handler": empty_handler})
asyncio.run(empty_worker_api._sim_run(default_input_object))
empty_status_return = asyncio.run(empty_worker_api._sim_status("test-123"))
assert empty_status_return == {
"id": "test-123",
"status": "COMPLETED",
"output": {},
}

# Test webhook caller sent
asyncio.run(worker_api._sim_run(input_object_with_webhook))
asyncio.run(worker_api._sim_status("test-123"))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_serverless/test_modules/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ async def test_job_with_refresh_worker(self):

job_result = await rp_job.run_job(mock_handler, self.sample_job)

assert job_result["stopPod"] is True
assert job_result == {"stopPod": True}

async def test_job_bool_output(self):
"""
Expand Down