G
YouTube TikTok Games
Skip to content

Implement Pydantic Aliases #681

Open

Description

@pa-mike

Hello!

Great work with Ormar so far, been a real pleasure using it!

As originally posted by @collerek in #315 (comment), it appears that pydantic aliases are not yet supported.

Currently we are working with ormar to deal with data generated by another system, and are not able to control the keys of the data when it shows up as JSON. We have seen a few collisions between pydantic BaseModel attributes and keys we are encountering, and would love a clean way to keep these separate.

Any thoughts on how to manage this, or where we could dive into the repo at to implement this ourselves?

Is your feature request related to a problem? Please describe.
Problem: Need to be able to use pydantic alias, or manage models with fields whos name shadows pydantic BaseModel attributes. Currently encounter issues like:

NameError: Field name "validate" shadows a BaseModel attribute; use a different field name with "alias='validate'".

When attempting to use fields that shadow.

Describe the solution you'd like
Implement pydantic aliasing, to avoid issues with Field names shadowing pydantic BaseModel attributes

Describe alternatives you've considered
As a quick and dirty workaround that doesn't involve creating a second pydantic class, we are simply recursively renaming offending keys on deserialization, and reversing that process later.

Additional context
None

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions