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

It doesn't find by relation entity id #39

Open
resulyrt93 opened this issue Aug 28, 2023 · 3 comments
Open

It doesn't find by relation entity id #39

resulyrt93 opened this issue Aug 28, 2023 · 3 comments

Comments

@resulyrt93
Copy link

I'm using your excellent tool with beanie but i can't find a record by relation id. You can produce problem with following code block.

Reproduce Code

import asyncio

from beanie import init_beanie, Document, Link
from mongomock_motor import AsyncMongoMockClient


class School(Document):
    name: str

    class Settings:
        name = "school"


class Student(Document):
    name: str
    surname: str
    school: Link[School]

    class Settings:
        name = "student"


async def start_env():
    client = AsyncMongoMockClient()
    await init_beanie(database=client["test-db"], document_models=[School, Student])

    school = School(name="Harvard")
    await school.insert()

    student = Student(name="Barack", surname="Obama", school=school.id)
    await student.insert()

    harvard_students = await Student.find(Student.school.id == school.id).to_list()
    print("Harvard students: ", harvard_students)


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

Output

> Harvard students: []

requirements.txt

beanie==1.17.0
mongomock_motor==0.0.21

when I fetch all students or all schools i can see my insertions and relations between them.

Thank you.

@michaelkryukov
Copy link
Owner

Looks like duplicate of #5 and #20

@resulyrt93
Copy link
Author

So do you have any plan or suggestion to fix that issue? I checked duplicate issues but i couldn't find a solution :(

@michaelkryukov
Copy link
Owner

It's an issue with mongomock (mongomock/mongomock#759) that prevents beanie's Link from working. I don't really want to mock anything in this library, so this issue will persisnt until mongomock/mongomock#759 will be fixed. I might consider creating PR into mongomock, but I dont really have time for that right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants