Replies: 2 comments 4 replies
-
|
I'm having the same issue here. |
Beta Was this translation helpful? Give feedback.
3 replies
-
|
When you send To send empty value you should either omit this parameter: Or send empty value (browsers do this): But in current version the second request (with So, working solution: from typing import Annotated
from uuid import UUID
from fastapi import FastAPI, Form
from pydantic import BeforeValidator
from pydantic.json_schema import SkipJsonSchema
app = FastAPI()
@app.post("/")
async def nullable_param(
param: Annotated[
UUID | SkipJsonSchema[None],
Form(),
BeforeValidator(lambda v: v or None),
] = None,
):
return {"param": param} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
Request with empty value or without param will work as expected and return
{"param": null}But request with
param=nullwill fail:same for query params
Operating System
Other
Operating System Details
No response
FastAPI Version
0.104.1
Pydantic Version
2.4.2
Python Version
Python 3.11.1
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions