tortoise / tortoise/tortoise-orm
manager .filter and .all methods aren't returning QuerySet but a list
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the examples with Company.all() and Company.filter(active=True), then trace the manager and queryset entry points that implement those methods. Confirm the intended return type against the prefetch_related call; done means both calls support prefetch_related and the Pydantic list serialization path no longer raises the shown AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100