Closed dlionel closed 1 year ago
There's something wrong with how you structured it.
Merchant
should have atleast 1 field, mypy
will detect it because it has no attribute id
and you're accessing the id
Field
.
Also judging by the query you're using, you should be using it this way:
bar = await Review.find_one(Review.merchant.id == merchant.id)
from typing import Optional
from beanie import Link
from pydantic import Field
import beanie
class Merchant(beanie.Document):
id = Field(None, alias="_id")
class Review(beanie.Document):
merchant: Optional[Link[Merchant]]
async def list_reviews()-> None:
merchant = await Merchant.find_one()
assert merchant
Review.find_many(Review.merchant.id == merchant.id)
review = Review(merchant=merchant)
Try this one.
This issue is stale because it has been open 30 days with no activity.
This issue was closed because it has been stalled for 14 days with no activity.
Describe the bug When making query with related elements, mypy raise an attribut error for related fields. Even a field as obvious as
id
is flagged with an error.To Reproduce
Create a file:
test_beanie_link.py
Then run:
Expected behavior Expecting mypy to run without issue raised.
Instead got:
Additional context