Skip to content

fix(runtime): handle input=None in generic handler#286

Merged
deanq merged 6 commits intomainfrom
fix/AE-2317-generic-handler-input-none
Mar 26, 2026
Merged

fix(runtime): handle input=None in generic handler#286
deanq merged 6 commits intomainfrom
fix/AE-2317-generic-handler-input-none

Conversation

@deanq
Copy link
Copy Markdown
Member

@deanq deanq commented Mar 25, 2026

Summary

  • Fix AttributeError crash when malformed job sends {"input": null} to generic handler
  • Changed job.get("input", {}) to job.get("input") or {} in both create_handler and create_deployed_handler — the default {} only applies when the key is missing, not when it's explicitly null
  • Added tests for input=None and missing input key scenarios

Test plan

  • test_create_handler_input_none — verifies graceful error response instead of crash
  • test_create_handler_input_missing — verifies missing input key handled
  • All 2491 existing tests pass
  • Coverage at 85.79%

Fixes AE-2317

@deanq deanq requested a review from Copilot March 25, 2026 20:48
@deanq deanq force-pushed the fix/AE-2317-generic-handler-input-none branch from 369da3e to bb144f1 Compare March 25, 2026 20:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_handler and create_deployed_handler to treat job["input"] == None as an empty dict.
  • Add unit tests covering input=None and missing input key 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=None now normalized to {}, function_name becomes None and the handler returns "Function 'None' not found...". Consider explicitly detecting a missing/empty function_name and returning a clearer error (e.g., that job['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.

@deanq deanq force-pushed the fix/AE-2317-generic-handler-input-none branch from 7d92052 to 865c2e5 Compare March 25, 2026 23:14
@deanq deanq requested a review from Copilot March 25, 2026 23:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@runpod-Henrik runpod-Henrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_none passes 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

@deanq deanq force-pushed the fix/AE-2317-generic-handler-input-none branch from e04fddb to 7570a92 Compare March 26, 2026 20:20
deanq added 4 commits March 26, 2026 13:30
`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.
@deanq deanq force-pushed the fix/AE-2317-generic-handler-input-none branch from 7570a92 to 0e40657 Compare March 26, 2026 20:34
deanq added 2 commits March 26, 2026 14:02
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.
@deanq deanq merged commit cab2d0c into main Mar 26, 2026
4 checks passed
@deanq deanq deleted the fix/AE-2317-generic-handler-input-none branch March 26, 2026 23:20
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.

4 participants