FastAPI Update Fixes Sneaky Bug That Could Break Your App
If your app sends empty values, this update could save you from crashes.
JSON request bodies now distinguish an explicit null from an omitted value. For individual Body parameters, null is validated as None: nullable types accept it, while non-nullable types reject it even when a default is defined.
Defaults and default factories apply only when the value is omitted. This applies both to parameters inside JSON objects and to parameters representing the entire body.
Clients that used null to request a default should omit the value instead. When a JSON object is expected because of Body(embed=True) or multiple body parameters, sending null as the entire body now returns a validation error.
- FastAPI now treats null as a real value, not a request for a default.
- If you want a default, omit the field instead of sending null.
- Sending null as the entire body now causes a validation error.
Why It Matters
This update prevents hidden bugs and makes apps more reliable, saving developers time and frustration.