jazzband / jazzband/django-model-utils

InheritanceManager queries always return an instance of InheritanceQuerySet

Open
#522 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.8k
Forks
374
PR merge metrics
No merged PRs in 30d

Description

## Problem

I am using a custom model manager that extends `InheritanceManager` like so:

```
class Manager(InheritanceManager):
def custom_method(self):
return self.filter(...)
```

because the return type of `get_queryset()` of `InheritanceManagerMixin` is hardcoded to return `self._queryset_class(self.model)` it's impossible for me to chain the methods of my custom `Manager`:

`Model.objects.all().custom_method()` will fail since `.all()` will return an instance of `InheritanceQuerySet` and my `custom_method` isn't defined there, it's rather defined on `Manager`.

Although this slight confusion is mentioned in the documentation [here](https://django-model-utils.readthedocs.io/en/latest/managers.html#mixins) it's still not clear for the user how to properly extend `InheritanceManager` with custom managers

## Environment

- Django Model Utils version: 4.1.1
- Django version: 3.2.11
- Python version: 3.8

## Code examples

`Model.objects.custom_method()` works
`Model.objects.filter().custom_method()` fails with exception `'InheritanceQuerySet' object has no attribute 'custom_method'`

Contributor guide

Open the contributing guide

Research direction

Start with InheritanceManagerMixin.get_queryset() and the custom Manager example in the issue. Reproduce the difference between Model.objects.custom_method() and Model.objects.filter().custom_method() on Django 3.2. Done means chained querysets preserve access to the custom manager method without breaking existing InheritanceManager behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
database
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.