BeanieODM / beanie

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

[BUG] Got unknown type for Linked classes after 3nd level of Links. #822

Closed jeremos closed 5 months ago

jeremos commented 6 months ago

Hi,

First, Many thanks for your work on Beanie. It's a great and powerful ODM :) I use Beanie with a large object model with many nested objects.

[A] : Link [B] [B] : List[BackLink [A] ] [B] : Link [C] [C] : List[BackLink [B] ] [C] : Link [D] ...

I noticed the object type is "lost" after the third level and the BackLink type (in my case) is affected to objects after this level. When objects have to be serialized, Pydantic does not know how to serialize the object :

pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'beanie.odm.fields.BackLink'>

The actual way to bypass the trouble is to add a pydantic "exclude=True" on fields.

I also read in the Beanie documentation that only the second level of Links/BackLinks are correctly managed for now. So when you will work on multi level Links/BackLinks, it will be appreciated to specify a max Depth level under which one Objects will not be fetched.

Thank again

roman-right commented 6 months ago

Hi @jeremos , Thank you for the catch! Yup, python typing system, how pydantic uses it inside the Rust layer and what I can do with it is a complicated thing :) But yes, sure, I have to make Beanie be able to handle multilevel links. Thank you!

github-actions[bot] commented 5 months ago

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] commented 5 months ago

This issue was closed because it has been stalled for 14 days with no activity.