Open iterlace opened 1 year ago
Hi! Thank you for the catch. I'll check and fix it this/next week.
Hey :) Any updates here?
Hi @iterlace , Sorry for the late reply. Thank you very much for the detailed investigation. Could you please try this: https://github.com/roman-right/beanie/pull/797 I reworked revisions - there are no swaps more. But probably I didn't cover some corner cases.
💕 First of all, I want to thank you for such a great Pydantic-based library. I don't even want to imagine using any other ODM with embedded data types, validation mechanisms, etc.
Describe the bug When I migrated from 1.18.0 => 1.22.0, some of my tests started failing for no reason. Debugging showed that the cause was
beanie.odm.utils.parsing.parse_obj
.When
Model.model_validate(data)
is called against a Model instance (but not a dict), it returns the same Python object. Butparse_obj
doesn't seem to expect that, and still executessave_state_swap_revision(result)
->item._swap_revision()
.How to Reproduce
We could still initialize WindowWithRevision with
lock=lock.ref()
(and everything would work great), but what's the point?beanie.odm.utils.encoder.Encoder
properly encodesDocument
instances intoLink
on save, so there's no reason to do it manually.But that's not the problem that pushed me to write this issue. The resulting problem is far worse. Let's take another example, when
LockWithRevision
is fetched from the database.How did we get TWO calls to
LockWithRevision._swap_revision
?LockWithRevision
been initializing (1->2->3).beanie.odm.utils.parsing.parse_obj
duringWindowWithRevision(x=0, y=0, lock=lock)
.What does it mean for us? We can no longer push LockWithRevision to the DB, because
_previous_revision_id
no longer contains a realrevision_id
from the database, andDocument.update
will always update 0 rows.Expected behavior Document.revision_id is changed only when it is fetched from the DB. _Actually, I would like to have the revision_id changed directly in the
update
/replace
/... methods, but not inget
. So that two identical objects, fetched from the db, would be absolutely similar on Document level and comparable with==
operator. This is another pain point I wanted to mention. As of now, we can do nothing but compare .model_dump'ed dicts withrevision_id
excluded. That's a hell of an inconvenience._Final words I really hope this issue could be resolved in the upcoming release. Thank you!