Skip to content

fix: handle empty dict handler response without KeyError#1

Open
AmSach wants to merge 1 commit into
mainfrom
fix/keyerror-empty-handler-response
Open

fix: handle empty dict handler response without KeyError#1
AmSach wants to merge 1 commit into
mainfrom
fix/keyerror-empty-handler-response

Conversation

@AmSach
Copy link
Copy Markdown
Owner

@AmSach AmSach commented May 31, 2026

Bug Summary

When a Runpod handler returns an empty dict {}, the framework raises a KeyError in the FastAPI development endpoint.

Root cause: In rp_job.py, when a handler returns {}, the 'output' key gets removed before the result is returned (line ~207). However, in rp_fastapi.py, both _sim_runsync() and _sim_status() unconditionally access job_output['output'] at the return statement, causing a KeyError.

Fix

Changed job_output['output'] to job_output.get('output') in two locations:

  • _sim_runsync() (line 342)
  • _sim_status() (line 419)

This gracefully returns None when the 'output' key is absent, making the behavior consistent with documented expectations (returning {} from a handler is valid).

Testing

Verified by analysis of the code flow:

  1. Handler returns {}
  2. rp_job.py sees run_result.get('output') == {} and calls run_result.pop('output')
  3. run_result becomes {}
  4. Back in rp_fastapi.py, job_output = {}
  5. Before fix: job_output['output']KeyError: 'output'
  6. After fix: job_output.get('output') → returns None, serialized as null

Fixes #459

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 runpod#459
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Returning empty object from handler raises KeyError exception within framework

1 participant