fix: handle empty dict handler response without KeyError#1
Open
AmSach wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Summary
When a Runpod handler returns an empty dict
{}, the framework raises aKeyErrorin 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, inrp_fastapi.py, both_sim_runsync()and_sim_status()unconditionally accessjob_output['output']at the return statement, causing aKeyError.Fix
Changed
job_output['output']tojob_output.get('output')in two locations:_sim_runsync()(line 342)_sim_status()(line 419)This gracefully returns
Nonewhen 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:
{}rp_job.pyseesrun_result.get('output') == {}and callsrun_result.pop('output')run_resultbecomes{}rp_fastapi.py,job_output = {}job_output['output']→KeyError: 'output'job_output.get('output')→ returnsNone, serialized asnullFixes #459