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] fetch links query does not recognize criteria with link's id inside $or operator #631

Closed
IterableTrucks opened this issue Jul 25, 2023 · 4 comments
Labels

Comments

@IterableTrucks
Copy link
Contributor

IterableTrucks commented Jul 25, 2023

Describe the bug
query with fetch_links=True does not recoginize criteria including link's ref id when it is parenthesized in an Or operator.

To Reproduce

import asyncio
from beanie import Document, Link, init_beanie, PydanticObjectId
from beanie.operators import Or


class Directory(Document):
    name: str


class File(Document):
    name: str
    size: int
    directory: Link[Directory]


async def main():
    await init_beanie(connection_string="mongodb://localhost:27017/test", document_models=[Directory, File])
    directory = await Directory(name="dir-2").insert()
    await File(name="file-2", size=5, directory=directory).insert()
    files = await File.find(Or(File.size > 10, File.directory.id == directory.id), fetch_links=True).to_list()
    # does not find any files
    print(files)
    files = await File.find(File.directory.id == directory.id, fetch_links=True).to_list()
    # produces correct files
    print(files)

asyncio.run(main())

Expected behavior
Or criteria can be rendered correctly

Additional context
beanie version = 1.20.0 MongoDB version = 6.0.6

@github-actions
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 Aug 25, 2023
@IterableTrucks
Copy link
Contributor Author

This bug still exists in 1.21.0

@github-actions github-actions bot removed the Stale label Aug 31, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 1, 2023

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

@github-actions github-actions bot added the Stale label Oct 1, 2023
@github-actions
Copy link
Contributor

This issue was closed because it has been stalled for 14 days with no activity.

roman-right pushed a commit that referenced this issue Oct 22, 2023
* fix: convert link field id within operators

* fix lint & mypy type error

---------

Co-authored-by: IterableTrucks <IterableTrucks@localhost>
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