You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pydantic allows list's element with nested discriminated unions. Is there any elegant way to apply constraints (such as MaxLen, MinLen) on sublist based on inner discriminator without writing custom validator?
For example: In below PetModel, limit number of Cat to MinLen(1) and Dog to MaxLen(2)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Pydantic allows list's element with nested discriminated unions. Is there any elegant way to apply constraints (such as MaxLen, MinLen) on sublist based on inner discriminator without writing custom validator?
For example: In below
PetModel
, limit number ofCat
to MinLen(1) andDog
to MaxLen(2)Adapted from https://docs.pydantic.dev/latest/concepts/unions/#nested-discriminated-unions
Beta Was this translation helpful? Give feedback.
All reactions