BeanieODM / beanie

Asynchronous Python ODM for MongoDB

Home Page:http://beanie-odm.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Slient invalid document link resolution

thorin-schiffer opened this issue · comments

Describe the bug
When a document has a invalid link, fetch_links=True results in a silent non-resolution to the Link object. This is a hardly debuggable case if a collection of objects is fetched.

To Reproduce
So if attribute requires a domain

class Domain(Document):
    ...

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

and the linked domain was removed, requesting a collection like await Attribute.all(fetch_links=True).to_list() will have both resolved and unresolved links to domain, which is hard to distinguish from await Attribute.all().to_list() without fetched links.

Expected behavior
I would prefer an exception, but alternatively another type can be set, like UnresolvableLink, or None or Link instance with some flag.

Hi! Thank you for the issue. I'll think about the interface for this