Werk #22207 · Sep 21, 26
REST API: wrong field type is now a 400
Previously, sending a value of the wrong JSON type to a REST API field -- a
number where a string belongs, say {"site_id": 5} -- made the request fail
with HTTP 500 and left a crash report behind. Malformed input never deserved
that: the request now fails with HTTP 400 and names the offending field, like
every other invalid value, and no crash report is written.
This affects a broad part of the API surface, since around 75 fields across the endpoints validate their input this way.
Technical background
The affected fields validate through TypedPlainValidator, which raised a
TypeError when the input did not match the declared type. Pydantic only
turns ValueError and AssertionError raised inside a validator into a
validation error, so the TypeError escaped request validation entirely and
was caught by the WSGI catch-all, which answers with a crash report. The
validator now raises ValueError.
Details
- Class:
- Bug Fixes
- Level:
- Prominent
- Component:
- REST API
- Versions:
- 3.0.0b1Not yet releasedAll Editions