tortoise / tortoise/tortoise-orm

Bug in nested QuerySet when defined via `objects = CustomManager(...)`

Open
#917 0 comments 0 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

In continuation to https://github.com/tortoise/tortoise-orm/issues/864

Now it works if manager is defined like this:

class ManagerModel(AbstractManagerModel):
    class Meta:
        manager = StatusManager(queryset_cls=StatusQuerySet)

(Thats from tests/testmodels.py)

However it will not work if manager is defined like this:

class ManagerModel(AbstractManagerModel):
    objects = StatusManager(queryset_cls=StatusQuerySet)

However it works, when in tortoise/queryset.py:321

- queryset = self.__class__.__new__(QuerySet)
+ queryset = self.__class__.__new__(self.__class__)

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

Start with the ManagerModel definitions in tests/testmodels.py and inspect tortoise/queryset.py around line 321. Reproduce the difference between defining StatusManager through Meta.manager and objects, then verify that the objects form preserves the StatusQuerySet behavior shown in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
database
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.