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: 0 additions & 3 deletions runpod/serverless/modules/rp_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,6 @@ async def run_job(handler: Callable, job: Dict[str, Any]) -> Dict[str, Any]:
else:
run_result = {"output": job_output}

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

check_return_size(run_result) # Checks the size of the return body.

except Exception as err:
Expand Down
13 changes: 13 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,19 @@ def test_runsync(self):
"output": {"result": "success"},
}

# Empty dict outputs should be returned as valid results rather
# than raising KeyError while building the runsync response.
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
11 changes: 11 additions & 0 deletions tests/test_serverless/test_modules/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
class TestJob(IsolatedAsyncioTestCase):
"""Tests for the get_job function."""

async def test_run_job_preserves_empty_dict_output(self):
"""Empty dict handler results are valid outputs."""

def handler(job):
del job
return {}

result = await rp_job.run_job(handler, {"id": "test-job", "input": {}})

self.assertEqual(result, {"output": {}})

async def test_get_job_200(self):
"""Tests the get_job function with a valid 200 response."""
# Mock the 200 response
Expand Down