Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#19151 closed Bug (fixed)

EmptyQuerySet is missing overrides for values() and values_list() methods.

Reported by: Bradley Ayers <brad@…> Owned by: Architekt
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

AnonymousUser.groups breaks down it's facade with values(), values_list():

>>> AnonymousUser().groups.values_list('name')
Traceback (most recent call last):
  File "<snip>", line 1, in <module>
  File "<snip>/django/db/models/manager.py", line 182, in values_list
    return self.get_query_set().values_list(*args, **kwargs)
  File "<snip>/django/db/models/query.py", line 585, in values_list
    _fields=fields)
  File "<snip>/django/db/models/query.py", line 1138, in _clone
    c = super(EmptyQuerySet, self)._clone(klass, setup=setup, **kwargs)
  File "<snip>/django/db/models/query.py", line 864, in _clone
    c._setup_query()
  File "<snip>/django/db/models/query.py", line 988, in _setup_query
    self.query.add_fields(self.field_names, True)
  File "<snip>/django/db/models/sql/query.py", line 1643, in add_fields
    alias = self.get_initial_alias()
  File "<snip>/django/db/models/sql/query.py", line 840, in get_initial_alias
    alias = self.join((None, self.model._meta.db_table, None, None))
AttributeError: 'NoneType' object has no attribute '_meta'
>>> AnonymousUser().groups.values_list()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "<snip>/django/db/models/manager.py", line 182, in values_list
    return self.get_query_set().values_list(*args, **kwargs)
  File "<snip>/django/db/models/query.py", line 585, in values_list
    _fields=fields)
  File "<snip>/django/db/models/query.py", line 1138, in _clone
    c = super(EmptyQuerySet, self)._clone(klass, setup=setup, **kwargs)
  File "<snip>/django/db/models/query.py", line 864, in _clone
    c._setup_query()
  File "<snip>/django/db/models/query.py", line 982, in _setup_query
    self.field_names = [f.attname for f in self.model._meta.fields]
AttributeError: 'NoneType' object has no attribute '_meta'

Change History (5)

comment:1 Changed 2 years ago by Architekt

  • Component changed from contrib.auth to Database layer (models, ORM)
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to Architekt
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Summary changed from AnonymousUser().groups.value_list('name') raises AttributeError to EmptyQuerySet is missing overrides for values() and values_list() methods.

comment:2 Changed 2 years ago by Architekt

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 2 years ago by Architekt

  • Has patch set
  • Triage Stage changed from Accepted to Ready for checkin
  • Version changed from 1.4 to master

comment:4 Changed 2 years ago by Jan Bednařík <jan.bednarik@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In b87e2f46c80d15abcda0e181ab894fb938ceb12f:

Fixed #19151 -- Added missing methods to EmptyQuerySet.

Added values() and values_list() methods to EmptyQuerySet.

comment:5 Changed 2 years ago by Alex Gaynor <alex.gaynor@…>

In 6b0d93df18a5c265f87ee6e64dbdffbdecfcea4f:

Merge pull request #456 from JanBednarik/ticket_19151

Fixed #19151 -- Added missing methods to EmptyQuerySet.

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