Expose pydantic's Field(validation_alias=,serialization_alias=...) parameter#988
Expose pydantic's Field(validation_alias=,serialization_alias=...) parameter#988evotodi wants to merge 6 commits intofastapi:mainfrom
Conversation
In the SQLModel's main file, the "serialization_alias" parameter has been added. This allows to handle serialization separately if necessary. Simultaneously, a check has been added to pop the "serialization_alias" attribute if it's not present in PydanticFieldInfo.
In the main sqlmodel, validation_alias and serialization_alias have been added as optional attributes. These aliases would provide more flexibility in handling and managing data validation and serialization respectively.
| if not hasattr(PydanticFieldInfo, "validation_alias"): | ||
| kwargs.pop("validation_alias") | ||
| if not hasattr(PydanticFieldInfo, "serialization_alias"): | ||
| kwargs.pop("serialization_alias") |
There was a problem hiding this comment.
This doesn't look necessary (PydanticFieldInfo seems to accept kwargs even if it doesn't use them later)
|
Dear all, it would be totally awesome to release this. The issue exists several months and several versions already #725. Please, let's get some traction here :) |
|
second the push to get this merged as soon as possible please 🙏 |
|
@evotodi, thanks for your interest! Could you please add test that fails on current version and is fixed by this PR? |
|
As this PR has been waiting for the original user for a while but seems to be inactive, it's now going to be closed. But if there's anyone interested, feel free to create a new PR. |
This expands upon and closes PR #774 by adding serialization_alias and missing Field override parameters.
Allows for serializing json using serialization_alias when by_alias is true
object.model_dump_json(by_alias=True)