Skip to content

Commit 7768015

Browse files
authored
Pydantic 'alias' bug
This workaround fixes Pydantic serialization/deserialization while not modifying the internal alias logic. I cannot figure out why alias is not being passed through anymore. For example, I was needing to add schema_extra with these key values in order to read data from a Json with different field names. Thank you for your consideration.
1 parent 7256820 commit 7768015

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

sqlmodel/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ def Field(
387387
schema_extra: Optional[Dict[str, Any]] = None,
388388
) -> Any:
389389
current_schema_extra = schema_extra or {}
390+
391+
if alias:
392+
current_schema_extra['validation_alias'] = alias
393+
current_schema_extra['serialization_alias'] = alias
394+
390395
field_info = FieldInfo(
391396
default,
392397
default_factory=default_factory,

0 commit comments

Comments
 (0)