Opened 9 years ago

Closed 9 years ago

#24911 closed Bug (fixed)

QuerySet is initiated with model=None as kwarg, but is called in BaseManager.get_queryset() as arg.

Reported by: Jonas Degrave Owned by: Jonas Degrave
Component: Database layer (models, ORM) Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Jonas Degrave)

QuerySet is initiated with model=None as named argument a.k.a. kwarg:

class QuerySet(object):
     def __init__(self, model=None, query=None, using=None, hints=None):

But it is called in get_queryset() as positional argument a.k.a. arg:

def get_queryset(self):
        return self._queryset_class(self.model, using=self._db, hints=self._hints)

This causes trouble when overriding get_queryset (which is the idea behind the method) and using super(BlaBlaManager, self).get_queryset() which returns a non-standard queryset-class, where model is not necessarily the first argument, which should have been okay as model is a named argument.

Proposed solution:
in db/models/manager.py

def get_queryset(self):
        return self._queryset_class(model=self.model, using=self._db, hints=self._hints)

Github pull request: https://github.com/django/django/pull/4745

Change History (7)

comment:1 by Jonas Degrave, 9 years ago

Description: modified (diff)

comment:2 by Jonas Degrave, 9 years ago

Has patch: set

comment:3 by Tim Graham, 9 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:4 by Jonas Degrave, 9 years ago

Needs tests: unset
Owner: changed from nobody to Jonas Degrave
Status: newassigned

comment:5 by Jonas Degrave, 9 years ago

Resolution: fixed
Status: assignedclosed

comment:6 by Jonas Degrave, 9 years ago

Resolution: fixed
Status: closednew

comment:7 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 4352e865:

Fixed #24911 -- Made BaseManager.get_queryset() allow custom queryset args.

Note: See TracTickets for help on using tickets.
Back to Top