BeanieODM / beanie

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

[BUG] Multi-model pattern #801

Closed CAPITAINMARVEL closed 3 days ago

CAPITAINMARVEL commented 10 months ago

Describe the bug

"Never" is not awaitablePylancereportGeneralTypeIssues Could not bind method "find" because "type[Parent]" is not assignable to parameter "cls" Type "Parent" cannot be assigned to type "Document" "Parent" is incompatible with "Document"PylancereportGeneralTypeIssues (method) find: Never

"Never" is not awaitablePylancereportGeneralTypeIssues (function) to_list: Never

To Reproduce

from beanie import Document, UnionDoc

class Parent(UnionDoc):  # Union
    class Settings:
        name = "union_doc_collection"  # Collection name
        class_id = "_class_id"  # _class_id is default beanie internal field used to filter children Documents

class One(Document):
    int_field: int = 0
    shared: int = 0        

    class Settings:
        name = "One" # Name used to filer union document 'One', default to class name
        union_doc = Parent

class Two(Document):
    str_field: str = "test"
    shared: int = 0

    class Settings:
        union_doc = Parent

async def example():
    db = AsyncIOMotorClient(config._DB_CONNECT, compressors='zstd', tz_aware=True).LOTR
    await init_beanie(database=db, document_models=[Parent, One, Two])  # type: ignore
    data = await Parent.find().to_list()

if __name__ == "__main__":
    asyncio.run(example())

Expected behavior This bug is very annoying I expect it display a list of Parent but instead its unknown and full of error Im expecting it display data: list[Parent] = await Parent.all().to_list() # type: ignore

Additional context

github-actions[bot] commented 9 months ago

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

roman-right commented 9 months ago

Hi @CAPITAINMARVEL , thank you for the catch. Sorry for the delay, it was a crazy end of the year for me. May I ask, why did you close the PRs? They are not working properly?