Return default values of submodel #9297
Closed
mguyard
started this conversation in
Pydantic V2
Replies: 2 comments 2 replies
-
Yes, because your passing none to that field. You need a field validator to return an instance of position in the case of none. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Thank you.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I don't find how i can retreive default value of a submodel in case of my parent model is empty.
In my project, i use Pydantic for parsing/validate a configuration.
My Configuration :
In this situation, only the key position is set (all content of position is commented).
My code :
I want when i'm in this situation (None in position), use all default values of PositionConfig.
After multiple research, i've add a default value for also position :
But i've still this error :
If i comment position key in my configuration, this works and all default values are used but i want to manage the case of users forget to comment the position key.
If someone can help me to understand my error, this will be very appreciated.
Thank you
Beta Was this translation helpful? Give feedback.
All reactions