Skip to content

Commit

Permalink
Enable populate_by_name to handle aliases
Browse files Browse the repository at this point in the history
I'm not sure if this is a work-around for a bug, or a needed option in Pydantic.

See:
- BeanieODM/beanie#369
- https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.populate_by_name
  • Loading branch information
felddy committed Oct 18, 2024
1 parent a593d2d commit 86b493a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cyhy_db/models/place_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class PlaceDoc(Document):
"""The place document model."""

model_config = ConfigDict(extra="forbid")
model_config = ConfigDict(extra="forbid", populate_by_name=True)

class_: str = Field(alias="class") # 'class' is a reserved keyword in Python
country_name: str
Expand Down
4 changes: 3 additions & 1 deletion src/cyhy_db/models/ticket_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
class EventDelta(BaseModel):
"""The event delta model."""

from_: Optional[bool | float | int | str] = Field(..., serialization_alias="from")
model_config = ConfigDict(populate_by_name=True)

from_: Optional[bool | float | int | str] = Field(..., alias="from")
key: str = Field(...)
to: Optional[bool | float | int | str] = Field(...)

Expand Down

0 comments on commit 86b493a

Please sign in to comment.