Do the Pydantic features 'alias' and 'allow_population_by_field_name' work with Ormar? #315
-
I'm converting to using Ormar and before switching I was using the 'alias' field option on some specific Pydantic fields. However, when I try to create new Ormar objects and insert values using the alias (rather than the direct field name), I keep getting Pydantic validation errors saying that the required field is empty. I set the 'allow_population_by_field_name' option to 'True' in the Pydantic config class, so it should work. This problem seems to imply that the field isn't getting populated as expected. Does the way Ormar work somehow break this Pydantic feature? I can easily image that because the Pydantic field names and SQL column names are the same in an Ormar model, that it might not be supported without explicitly adding extra handling code. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, as of now pydantic aliases are not supported. You can have different database column name (if you provide Might be a possible enhancement. |
Beta Was this translation helpful? Give feedback.
Yes, as of now pydantic aliases are not supported.
You can have different database column name (if you provide
name
attribute for a field), so it's already two different names to handle, didn't want to add a third one as this would complicate things.Might be a possible enhancement.