#25252: Queryset with 'values' and 'select_related' won't work
-------------------------------------+-------------------------------------
     Reporter:  2roy999              |      Owner:  nobody
         Type:  Bug                  |     Status:  new
    Component:  Database layer       |    Version:  1.8
  (models, ORM)                      |   Keywords:  queryset values
     Severity:  Normal               |  select_related
 Triage Stage:  Unreviewed           |  Has patch:  0
Easy pickings:  0                    |      UI/UX:  0
-------------------------------------+-------------------------------------
 Trying to use a queryset while using both methods 'values' and
 'select_related' will throw an error when trying to use iter.

 models:

 {{{
 class Poll(models.Model):
     name = models.CharField(max_length=50L)

 class Entry(models.Model):
     poll = models.ForeignKey(Poll)
     name = models.CharField(max_length=50L)
 }}}

 code:
 {{{
 >>> iter(Entry.objects.values('name').select_related('poll'))
 }}}

 error:
 {{{
 Traceback (most recent call last):
   File "<console>", line 1, in <module>
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/query.py", line 162, in __iter__
     self._fetch_all()
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/query.py", line 965, in _fetch_all
     self._result_cache = list(self.iterator())
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/query.py", line 1085, in iterator
     for row in self.query.get_compiler(self.db).results_iter():
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 794, in results_iter
     results = self.execute_sql(MULTI)
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 829, in execute_sql
     sql, params = self.as_sql()
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 378, in as_sql
     extra_select, order_by, group_by = self.pre_sql_setup()
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 48, in pre_sql_setup
     self.setup_query()
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 39, in setup_query
     self.select, self.klass_info, self.annotation_col_map =
 self.get_select()
   File "/*path_to_project*/env/local/lib/python2.7/site-
 packages/django/db/models/sql/compiler.py", line 207, in get_select
     klass_info['related_klass_infos'] = related_klass_infos
 TypeError: 'NoneType' object does not support item assignment

 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25252>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.3bba1d523f52352dd23ea4b046ab89b3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to