tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.68k stars 390 forks source link

manager .filter and .all methods aren't returning QuerySet but a list #1399

Open joaoariedi opened 1 year ago

joaoariedi commented 1 year ago

Describe the bug The manager .filter and .all methods aren't returning a QuerySet and it's bugging the pydantic serializations for lists.

To Reproduce

>>> from app.companies.models import Company
>>> await Company.all()
[<Company: 1>, <Company: 2>, <Company: 3>]

>>> type(await Company.all())
<class 'list'>

>>> await Company.filter(active=True)
[<Company: 1>, <Company: 2>, <Company: 3>]

>>> type(await Company.filter(active=True))
<class 'list'>
    __root__=[submodel.from_orm(e) for e in await queryset.prefetch_related(*fetch_fields)]
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'prefetch_related'

Expected behavior A QuerySet object should returns.