Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] save() results in OperationFailure if use_revision=True and keep_nulls=False #958

Open
poccio opened this issue Jul 1, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@poccio
Copy link

poccio commented Jul 1, 2024

Describe the bug
Defining a document with use_revision=True and keep_nulls=False results in .save() raising OperationFailure when invoked on new documents. I am using beanie==1.26.0.

To Reproduce

import asyncio
import os

from beanie import Document, init_beanie
from motor.motor_asyncio import AsyncIOMotorClient


class Parent(Document):
    name: str

    class Settings:
        name = "parents"
        use_revision = True
        keep_nulls = False


async def main():
    client = AsyncIOMotorClient(os.environ["MONGO_URI"])
    await init_beanie(database=client.test, document_models=[Parent])

    # raises OperationFailure
    parent = Parent(name="P1")
    await parent.save()

    # works
    parent = Parent(name="P2")
    await parent.insert()


if __name__ == "__main__":
    asyncio.run(main())

Expected behavior
I would expect .save() to successfully insert the new document, as stated in the docs.

Additional context
I did some debugging and - I may be wrong but - the issue seems to be with the update query:

{
    "$set": {
        ..., 
        "revision_id": Binary(...)
    }, 
    "$unset": {
        "revision_id": None
    }
}

which tells Mongo to both set revision_id to a value and unset it. This is a result of this Unset operator, which specifies to unset revision_id (as it is, at that point, a top-level None).

(First issue here, thanks for the amazing library)

Copy link
Contributor

github-actions bot commented Aug 1, 2024

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Stale label Aug 1, 2024
@adeelsohailahmed adeelsohailahmed added bug Something isn't working and removed Stale labels Aug 16, 2024
@staticxterm
Copy link

Hi, thank you for the bug report!

It seems there are at least two unique issues concerning keep_nulls=False usage. See also: #1048 (duplicate)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants