BeanieODM / beanie

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

[BUG] Slient invalid document link resolution #872

Open thorin-schiffer opened 7 months ago

thorin-schiffer commented 7 months ago

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.

roman-right commented 7 months ago

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