fix(runtime): handle input=None in generic handler#286
Conversation
369da3e to
bb144f1
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a runtime crash in the generic handler when a malformed job payload provides {"input": null} by ensuring handler code can safely proceed without AttributeError.
Changes:
- Update
create_handlerandcreate_deployed_handlerto treatjob["input"] == Noneas an empty dict. - Add unit tests covering
input=Noneand missinginputkey for both handler factories.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/runpod_flash/runtime/generic_handler.py |
Normalizes job["input"] to {} when falsy to avoid .get() crashes. |
tests/unit/runtime/test_generic_handler.py |
Adds regression tests for input=None and missing input scenarios for both handler types. |
Comments suppressed due to low confidence (1)
src/runpod_flash/runtime/generic_handler.py:176
- With
input=Nonenow normalized to{},function_namebecomesNoneand the handler returns "Function 'None' not found...". Consider explicitly detecting a missing/emptyfunction_nameand returning a clearer error (e.g., thatjob['input']['function_name']is required) to make malformed-job debugging easier.
job_input = job.get("input") or {}
function_name = job_input.get("function_name")
execution_type = job_input.get("execution_type", "function")
if function_name not in function_registry:
return {
"success": False,
"error": f"Function '{function_name}' not found in registry. "
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7d92052 to
865c2e5
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
runpod-Henrik
left a comment
There was a problem hiding this comment.
PR #286 — fix(runtime): handle input=None in generic handler
Repo: runpod/flash
Severity: LOW
Key findings: Crash on null input is fixed. Two remaining gaps: missing test for one handler variant, and inconsistent error schemas between the two handler types.
1. Missing test: deployed handler with no input key
create_deployed_handler now handles the case where the input key is absent from the job entirely (job = {}). There is no test for this path. The create_handler variant has an equivalent test, but the deployed handler variant only tests {"input": null}. If the missing-key path is broken, nothing will catch it.
User scenario: a caller sends a malformed job payload to a deployed endpoint with no input field — this path fires and is untested.
2. Inconsistent error schema between the two handler types
When input is invalid, the two handlers return different error shapes. One includes a success: false field; the other returns only {"error": ...} with no success key. If any client code checks response["success"] on the deployed handler's error response, it gets a KeyError instead of the expected boolean.
This inconsistency pre-existed for the crash path and is now extended to the new type-guard branches. This PR is a good opportunity to align them.
Nits
test_create_handler_input_nonepasses because null input routes through a "function not found" path rather than an explicit null-input rejection path. A comment in the test explaining why "not found" is the expected message would prevent future confusion about what this test is actually verifying.
Verdict
PASS WITH NITS — the crash fix is correct. Add a test for create_deployed_handler with a missing input key, and consider aligning the error schema between the two handlers before the mismatch causes a client-side bug.
🤖 Reviewed by Henrik's AI-Powered Bug Finder
e04fddb to
7570a92
Compare
`job.get("input", {})` returns None when input is explicitly null,
causing AttributeError on the subsequent `.get()` call. Use `or {}`
to coalesce both missing and null input to empty dict.
Fixes AE-2317
- Add tests for create_deployed_handler with input=None and missing input - Tighten create_handler assertions to verify "not found" error message
Address review feedback: replace `or {}` with explicit `is None` check
and add type validation to reject non-dict input types. Remove duplicate
test_create_deployed_handler_input_missing (covered in deployed handler
tests). Add type-validation tests for both handlers.
Add test for create_deployed_handler with missing input key (job = {}).
Add success: False to deployed handler error returns to match
create_handler error schema.
7570a92 to
0e40657
Compare
Replace cloudpickle with Pydantic model_validate round-trip in test_pickled_resource_preserves_id — cloudpickle + Pydantic v2 produces corrupt schemas under pytest-xdist parallel execution. Create .flash/ directory in mock_resource_file fixture — the .runpod to .flash migration changed the state directory but the fixture was not updated to create the new parent directory.
Release workflow tested 3.9 and 3.13 which are outside the supported range (>=3.10,<3.13). Align with ci.yml: 3.10, 3.11, 3.12.
Summary
AttributeErrorcrash when malformed job sends{"input": null}to generic handlerjob.get("input", {})tojob.get("input") or {}in bothcreate_handlerandcreate_deployed_handler— the default{}only applies when the key is missing, not when it's explicitlynullinput=Noneand missinginputkey scenariosTest plan
test_create_handler_input_none— verifies graceful error response instead of crashtest_create_handler_input_missing— verifies missing input key handledFixes AE-2317