mongomock_motor
mongomock_motor copied to clipboard
It doesn't find by relation entity id
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.
Looks like duplicate of #5 and #20
So do you have any plan or suggestion to fix that issue? I checked duplicate issues but i couldn't find a solution :(
It's an issue with mongomock (https://github.com/mongomock/mongomock/issues/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 https://github.com/mongomock/mongomock/issues/759 will be fixed. I might consider creating PR into mongomock, but I dont really have time for that right now