You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I have a before_event annotation to update a field on a document every time it is updated. The behavior the event handling is inconsistent based on what update method I use. I have a full reproduction that shows updating 4 documents in 4 different ways, with differing results:
find_one(...).update(...) - Not triggered, tag field NOT set in db
find_one(...); result.update(...) - Triggered ONCE, tag field NOT set in db
find_one(...); result.set(...) - Triggered ONCE, tag field NOT set in db
find_one(...); result.field = val; result.save() - Triggered TWICE; tag field SET in db
Expected behavior
I'm unsure of whether or not the before_event should be triggered twice during the 4th case (find, update, save()), but for all 4 cases I would expect the before_event to get triggered at least once, and I would expect the final value in the DB to have a "tag": "updated" value.
Additional context
I'm particularly interested in the behavior of the first case, where .update() is called directly on the result of find_one() - I would like to use this pattern with a before_event annotation to automatically set an updatedAt field on my documents.
The repro code can be run with beanie installed and an empty mongodb instance (I used the mongo:5 docker image, but I suspect a local instance would work as well).
Python version: 3.10.10
Beanie version: 1.28.0
The text was updated successfully, but these errors were encountered:
Describe the bug
I have a
before_event
annotation to update a field on a document every time it is updated. The behavior the event handling is inconsistent based on what update method I use. I have a full reproduction that shows updating 4 documents in 4 different ways, with differing results:find_one(...).update(...)
- Not triggered, tag field NOT set in dbfind_one(...); result.update(...)
- Triggered ONCE, tag field NOT set in dbfind_one(...); result.set(...)
- Triggered ONCE, tag field NOT set in dbfind_one(...); result.field = val; result.save()
- Triggered TWICE; tag field SET in dbTo Reproduce
Expected behavior
I'm unsure of whether or not the
before_event
should be triggered twice during the 4th case (find, update, save()), but for all 4 cases I would expect thebefore_event
to get triggered at least once, and I would expect the final value in the DB to have a"tag": "updated"
value.Additional context
I'm particularly interested in the behavior of the first case, where
.update()
is called directly on the result offind_one()
- I would like to use this pattern with abefore_event
annotation to automatically set anupdatedAt
field on my documents.The repro code can be run with beanie installed and an empty mongodb instance (I used the
mongo:5
docker image, but I suspect a local instance would work as well).Python version: 3.10.10
Beanie version: 1.28.0
The text was updated successfully, but these errors were encountered: