Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose pydantic's Field(validation_alias=,serialization_alias=...) parameter #988

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

evotodi
Copy link

@evotodi evotodi commented Jun 18, 2024

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)

rbubley and others added 5 commits January 8, 2024 16:24
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.
Copy link

@ixycoexzckwpmlcu ixycoexzckwpmlcu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look fine (other than the small nitpick below).

Comment on lines +154 to +157
if not hasattr(PydanticFieldInfo, "validation_alias"):
kwargs.pop("validation_alias")
if not hasattr(PydanticFieldInfo, "serialization_alias"):
kwargs.pop("serialization_alias")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look necessary (PydanticFieldInfo seems to accept kwargs even if it doesn't use them later)

@khrapovs
Copy link

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 :)

@HeiziND
Copy link

HeiziND commented Aug 8, 2024

second the push to get this merged as soon as possible please 🙏
I have to map thousands (yes thousands) of field names from a third-party API onto a local DB with different column names, and having to write schema_extra={"validation_alias": "some_thirdparty_name"}) hundreds of times is a chore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants