Skip to content
Discussion options

You must be logged in to vote

The best workaround I have found is to not type hint the return on the serializer. Then it will use the same definition as it would without the serializer defined.

    def clean_model(self, serializer: Any, info: SerializationInfo):  # type: ignore [no-untyped-def]

From the FastAPI side of things this is because it calls .model_json_schema(mode="serialization") and typing the return of the serializer changes what pydantic returns for the serialization mode. I feel like what FastAPI is doing is correct and the root of the issue is on the pydantic side. I wrote up an issue on pydantic requesting a nicer way to handle this: pydantic/pydantic#8791 if anyone wants thumbs up it or chime in with…

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@alex-pobeditel-2004
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
5 participants