Git Product home page Git Product logo

Comments (3)

roman-right avatar roman-right commented on June 16, 2024 2

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.

mikeckennedy avatar mikeckennedy commented on June 16, 2024

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.

RamonGiovane avatar RamonGiovane commented on June 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.