Repository navigation
fix(api): dispatch native routes by their declared input - #13
Conversation
justinwlin
left a comment
There was a problem hiding this comment.
The fix is right and the tests are thorough. Two notes inline, not blocking.
| else: | ||
| signature = inspect.signature(fn) | ||
|
|
||
| if signature.parameters: |
There was a problem hiding this comment.
This rule is "any argument means the handler needs a body". It is only correct when the SDK has already refused handlers like this one:
@get("/search")
def search(self, q="hello"):
return {"q": q}q has a default, so the handler does not need a body. But this line sees one argument and requires one. A GET has no body, so every call returns 422.
The SDK and this runtime ship separately, so there are four cases for this handler:
| SDK | Runtime | Result |
|---|---|---|
| Without runpod/runpod-python#713 | Without this PR | 200 (today) |
| With #713 | With this PR | Refused at import, clear error (intended) |
| With #713 | Without this PR | Refused at import, clear error |
| Without #713 | With this PR | Loads, then every request returns 422 Field required: body |
The last row is the problem. It can happen because the image and pyproject.toml accept any runpod>=2.2.0. The same applies to def opt(self, body=None) with no body, and to a handler behind a decorator without functools.wraps.
Can we release the SDK first, then raise the minimum version here and in docker/api.Dockerfile? After that the last row cannot occur.
Native API requests could fail with HTTP 500 when the supplied body did not match how the handler was called.
POST /refreshwith{}called this handler with an extra argument. A handler requiringbody: dictwas called without it when the request body was missing or null.Now native handlers are invoked according to their declared arguments. Body handlers receive one complete JSON object and reject missing, malformed, null, or non-object input with HTTP 422. No-argument handlers do not consume request bodies.
Declaration validation is covered by the companion SDK PR #713. Both releases are needed for the complete contract.
Refs CON-2064.