tortoise / tortoise/tortoise-orm

Subclassing of QuerySet

Open
#2,010 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Is there any plans for allowing developers to easily subclass querysets like in django? Currently, it seems like any subclass of a queryset returns the queryset, not the subclass.

Example:
class CustomQuerySet(QuerySet):
def get_active():

CustomQuerySet.filter().get_active()

The above is not chainable since .filter() returns an instance of QuerySet not CustomQuerySet.

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 at the QuerySet implementation and trace how filter constructs and returns querysets. Compare the intended chainability with the CustomQuerySet.get_active example, then determine how subclass preservation should be tested; the issue does not name a file or existing test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.