#15959: .values()/.values_list() fails on EmptyQuerySet
----------------------------+----------------------------------------------
 Reporter:  Davide Rizzo    |          Owner:  nobody
  <mail@…>                  |         Status:  new
     Type:  Bug             |      Component:  Database layer (models, ORM)
Milestone:                  |       Severity:  Normal
  Version:  1.2             |   Triage Stage:  Unreviewed
 Keywords:                  |  Easy pickings:  0
Has patch:  0               |
----------------------------+----------------------------------------------
 Calling .values() or .values_list() on an EmptyQuerySet raises an
 exception.
 {{{
 >>> EmptyQuerySet().values('id')
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
 515, in values
     return self._clone(klass=ValuesQuerySet, setup=True, _fields=fields)
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
 1049, in _clone
     c = super(EmptyQuerySet, self)._clone(klass, setup=setup, **kwargs)
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
 772, in _clone
     c._setup_query()
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
 895, in _setup_query
     self.query.add_fields(self.field_names, False)
   File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line
 1549, in add_fields
     alias = self.get_initial_alias()
   File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line
 798, in get_initial_alias
     alias = self.join((None, self.model._meta.db_table, None, None))
 AttributeError: 'NoneType' object has no attribute '_meta'
 }}}
 {{{
 >>> EmptyQuerySet().values_list('id')
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
 525, in values_list
     _fields=fields)
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
 1049, in _clone
     c = super(EmptyQuerySet, self)._clone(klass, setup=setup, **kwargs)
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
 772, in _clone
     c._setup_query()
   File "C:\Python27\lib\site-packages\django\db\models\query.py", line
 895, in _setup_query
     self.query.add_fields(self.field_names, False)
   File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line
 1549, in add_fields
     alias = self.get_initial_alias()
   File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line
 798, in get_initial_alias
     alias = self.join((None, self.model._meta.db_table, None, None))
 AttributeError: 'NoneType' object has no attribute '_meta'
 }}}

 This seems related to #7235. I can reproduce the bug on 1.2.4 and 1.2.5
 but not on 1.2.3.
 {{{
 ### Django 1.2.3
 >>> q = EmptyQuerySet()
 >>> q.values_list('id')
 []
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15959>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to