Skip to content
Discussion options

You must be logged in to vote

I see, that's helpful. I think longer term exclude_unset is the way to go here, but will require a little bit of a rework of how serialization happens.

In the short term I'm afraid manual handling is probably going to be necessary for this case.

One thing that might be convenient, depending on context, would be to override the dict or _iter or similar methods to remove keys with value None, if that is your goal. You could do that in a base class and get the logic reused. I believe that would result in FastAPI serializing the model the way you want. Obviously not ideal longer term (and maybe not even workable in the short term depending on how you are using things elsewhere), but might be …

Replies: 10 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by tiangolo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
Converted from issue

This discussion was converted from issue #528 on February 28, 2023 11:56.