-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Describe the bug
So if I am trying to run update for sync operations, using bunnet I need to use pydantic by_alias
inside model_dump
, while for beanie I don't need to do that.
Under the hood, I think the async Beanie update path and the sync Bunnet update path actually behave differently when it comes to your field‐name ↔ Mongo‐alias mapping.
To Reproduce
This is my update method using bunnet update.
def update(self, entity_id: Any, data: SyncT) -> SyncT:
"""
Update an entity.
Args:
entity_id: The ID of the entity to update
data: The updated entity data
Returns:
The updated entity
Raises:
ElementNotFoundException: If no entity with the given ID exists
"""
# Ensure entity exists
entity = self.get(entity_id)
# Update data fields
update_data = data.model_dump(exclude={"id"}, exclude_unset=True)
updated_entity = entity.update({"$set": update_data})
return updated_entity
This is my update method using beanie update
async def update(self, entity_id: Any, data: AsyncT) -> AsyncT:
"""
Update an entity.
Args:
entity_id: The ID of the entity to update
data: The updated entity data
Returns:
The updated entity
Raises:
ElementNotFoundException: If no entity with the given ID exists
"""
# Ensure entity exists
entity = await self.get(entity_id)
# Update data fields
update_data = data.model_dump(exclude={"id"}, exclude_unset=True)
updated_entity = await entity.update({"$set": update_data})
return updated_entity
as you can see they are almost identical. Now I have an entity that has an is_active
field, using beanie everything updates normally, but if I try to update the entity using bunnet is_active
fields gets ignored unless I specify by_alias=True
inside the model_dump
.
Expected behavior
I expect both libraries' update method to behave the same.