tortoise / tortoise/tortoise-orm

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

Open
#1,399 0 comments 2 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.