Comments (3)
I have to doublecheck,
In general RevisionIdWasChanged
can be raised, when insert part of upsert is trying to insert an object with already existing id, the native error there is that id already exists. It is a bit problematic to split all the valid cases and corner cases, where the actual duplication id error should be raised. I'll check both your cases. Thank you for the catch.
from beanie.
I've been getting crazy unexpected errors like this too. But my code is different:
podcasts = sorted(list(set(user.podcasts.copy() + [podcast.id])))
user.podcasts.clear()
user.podcasts.extend(podcasts)
await user.save()
I started with just await user.save()
but that didn't work, so I added ignore_revision=True
and still got the revision_id
changed error.
podcasts = sorted(list(set(user.podcasts.copy() + [podcast.id])))
user.podcasts.clear()
user.podcasts.extend(podcasts)
await user.save(ignore_revision=True)
So added the save original id, set it back, and STILL get the error.
revision_id = user.revision_id
podcasts = sorted(list(set(user.podcasts + [podcast.id])))
user.podcasts.clear()
user.podcasts.extend(podcasts)
user.revision_id = revision_id
await user.save(ignore_revision=True)
All of this is on top of the model saying no revision tracking.
class User(beanie.Document):
created_date: datetime.datetime = pydantic.Field(default_factory=datetime.datetime.now)
...
class Settings:
name = 'users'
use_revision = False
The document itself doesn't seem to have a revision_id in the DB at all:
{
"_id" : "65c456d339bfbd7af9f4b622",
"created_date" : "2024-02-07T20:21:39.439+0000",
"email" : "[email protected]",
"is_admin" : false,
"last_login" : "2024-02-07T20:21:39.439+0000",
"name" : "Michael",
"password_hash" : "$argon2id$v=19$m=65536,t=3,p=4$fg+hdO6dkjljljkLubfWug$QIUF4JPR/G3R5ElkjlkjlkjOIAZSvzyTwYAjmcdljljlkjg",
"podcasts" : [
"talk-python-to-me"
]
}
@roman-right What's happening? Any help? :)
from beanie.
I was doing some investigation myself and I found out that revision_id
is being lost between calls.
More precisely when we call save_changes()
, the self
object no longer has revision_id
:
> /home/ramon/Repos/beanie/error-test.py(73)_busines_logic()
-> await db_flow.save_changes() # ERROR!!! RevisionIdWasChanged
(Pdb) l
68
69 # Retrieving a fresh new instance from the inserted Flow in the DB
70 db_flow = await Flow.get(doc_flow.id, fetch_links=True, with_children=True)
71 db_flow.data = 'Some change'
72 breakpoint()
73 -> await db_flow.save_changes() # ERROR!!! RevisionIdWasChanged
74
75 async def _main():
76 await _init_db()
77 await _busines_logic()
78
(Pdb) db_flow.revision_id
UUID('fef90667-4d0d-4030-b372-001a085f36b1')
> /home/ramon/Repos/beanie/beanie/odm/documents.py(623)save_changes()
-> if not self.is_changed:
(Pdb) l
618 :param ignore_revision: bool - ignore revision id, if revision is turned on
619 :param bulk_writer: "BulkWriter" - Beanie bulk writer
620 :return: None
621 """
622 breakpoint()
623 -> if not self.is_changed:
624 return None
625 changes = self.get_changes()
626 if self.get_settings().keep_nulls is False:
627 return await self.update(
628 SetOperator(changes),
(Pdb) self.revision_id
(Pdb)
@roman-right is this a expected behavior?
Tested on 1.26.0.
from beanie.
Related Issues (20)
- [BUG]before_event bug HOT 4
- [BUG] Missing documentation for `beanie.odm.BulkWriter` HOT 1
- [BUG] (some) type annotations for session wrong HOT 3
- [BUG] type annotation for init_beanie() should use Sequence
- [BUG] before_event of type Update HOT 5
- [BUG] mypy does not raise error when trying to access a non-existing attribute from a beanie Document. HOT 1
- [BUG] Indexed unique will not work after Field regex. HOT 2
- [BUG] Empty BackLink for `Optional[BackLink[ADoc]]` when document has no back-link HOT 3
- Concerns and Suggestions Regarding Beanie Library HOT 2
- [Doc] Document for soft delete feature HOT 2
- [BUG] Order of elements in list[Link] is not preserved HOT 2
- [BUG] pydantic computed properties omitted during `insert_many` operation on Document HOT 1
- [BUG] get_motor_collection() returning None under volume only HOT 1
- [BUG] search criteria not using pydantic Field alias to set the key.
- [BUG] `PydanticObjectId` isn't properly configured when deserializing from JSON
- depth search "find(Teste.item1.item2.item3.id == id)" [BUG]
- [BUG] Link not working in find queries on fields with alias
- [BUG]
- [BUG] BulkWriter does not allow unordered bulks
- [BUG] `original_field` is not supported by pydantic, makes typecheckers give a type error and causes a warning at runtime
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from beanie.