🐛 [bug] FastAPI doesn't support Sentinel values. i.e.: Pydantic's MISSING. #14646
Replies: 2 comments 4 replies
-
|
This is indeed a limitation, but there are a few workarounds you can try: Workaround 1: Use Optional with custom validation Workaround 2: Use Field with default_factory from pydantic import BaseModel, Field
class Model(BaseModel):
value: str = Field(default_factory=lambda: "your_default")Workaround 3: Create your own Sentinel This is a known limitation in FastAPI/Pydantic that has been discussed in the community. Consider checking the Pydantic v2 documentation as newer versions may have better support for sentinel values. If you need this feature, I'd recommend opening an issue on the FastAPI GitHub repository to track this enhancement request. |
Beta Was this translation helpful? Give feedback.
-
|
@mvanderlee, would you like to open PR with your fix? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
https://github.com/fastapi/fastapi/blob/master/fastapi/dependencies/utils.py#L739
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.128.0
Pydantic Version
2.12.5
Python Version
3.13.10
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions