how to add a custom object field to request body's model with arbitrary_types_allowed=True? #13716
Unanswered
IterableTrucks
asked this question in
Questions
Replies: 1 comment · 1 reply
-
Was the code that you wrote working correctly before you upgraded to 0.115.12?
Here's a workaround that you can use which will work, just convert your from fastapi import FastAPI
from pydantic import BaseModel
from pydantic.json_schema import SkipJsonSchema
class Foo(BaseModel):
name: str
app = FastAPI()
class Item(BaseModel):
foo: SkipJsonSchema[Foo | None] = None
bar: str
@app.post('/')
async def create_item(item: Item) -> Item:
return item
|
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
-
First Check
Commit to Help
Example Code
Description
After upgrading to 0.115.12 from 0.112.4 the API cannot serve normally with a custom object field in its request body. The error is:
pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'arbitrary_request_field.Foo'>. Set
arbitrary_types_allowed=True
in the model_config to ignore this error or implement__get_pydantic_core_schema__
on your type to fully support it.If you got this error by calling handler() within
__get_pydantic_core_schema__
then you likely need to callhandler.generate_schema(<some type>)
since we do not call__get_pydantic_core_schema__
on<some type>
otherwise to avoid infinite recursion.For further information visit https://errors.pydantic.dev/2.11/u/schema-for-unknown-type
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.115.12
Pydantic Version
2.11.4
Python Version
3.13.2
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions