BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
2.02k stars 213 forks source link

[BUG] Multilevel related document lookups don't work #877

Open thorin-schiffer opened 7 months ago

thorin-schiffer commented 7 months ago

Describe the bug If document referencing goes further than one level, find won't resolve it properly

To Reproduce

class Organization(Document):
    slug: str

class Domain(Document):
    organization: Link[Organization]
    integration: str

class Attribute(Document):
    domain: Link[Domain]

class AttributeMapping(Document):
    source: Link[Attribute]
    target: Link[Attribute]

# won't work
await AttributeMapping.find(
            AttributeMapping.source.domain.integration == domain.integration,
            AttributeMapping.source.domain.organization.slug == organization.slug,
            fetch_links=True,
        ).count()

# won't work
await AttributeMapping.find(
            AttributeMapping.source.domain.id == domain.id,
            fetch_links=True, # regardless
        ).count()

Expected behavior Linked documents are found

roman-right commented 7 months ago

Hi! I'll check what is going on there and will let you know here if this is possible to fix or not. Thank you

alexkrytsky commented 2 months ago

@roman-right , is there any update on this since February? For the workaround, should the aggregation be used?