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] Wrong Typing for .find_one().inc() / .find_one().set() #1108

Open
HazyFish opened this issue Jan 15, 2025 · 1 comment
Open

[BUG] Wrong Typing for .find_one().inc() / .find_one().set() #1108

HazyFish opened this issue Jan 15, 2025 · 1 comment
Labels

Comments

@HazyFish
Copy link

HazyFish commented Jan 15, 2025

Describe the bug
Typing for .inc / .set is wrong when chained after .find_one.

To Reproduce

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


class ShortIdCounter(Document):
    value: int


async def main():
    MONGODB_CONNECTION_STRING = "mongodb://localhost"
    NEW_DB_NAME = "tmp-test"

    client = AsyncIOMotorClient(MONGODB_CONNECTION_STRING)

    await client.drop_database(NEW_DB_NAME)

    await init_beanie(
        database=client[NEW_DB_NAME],
        document_models=[
            ShortIdCounter,
        ],
    )

    id = PydanticObjectId()

    await ShortIdCounter(id=id, value=1).create()

    counter = await ShortIdCounter.find_one(ShortIdCounter.id == id).inc(
        {ShortIdCounter.value: 1},
    )

    print(counter)


if __name__ == "__main__":
    import asyncio

    asyncio.run(main())

Expected behavior

Expect counter to be an ShortIdCounter instance that contains the updated value, but got UpdateResult, which does not match the typing.

Additional context

Beanie version: v1.29.0

The behavior also mismatches the example in the documention: https://beanie-odm.dev/tutorial/updating-%26-deleting/#update-queries, which means either the typing and the documentation are both wrong or the implementation is wrong.

@HazyFish HazyFish changed the title [BUG] Wrong Typing for .find_one().inc() [BUG] Wrong Typing for .find_one().inc() / .find_one().set() Jan 15, 2025
Copy link
Contributor

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

@github-actions github-actions bot added the Stale label Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant