#25894: Paginator fails with QuerySet returning no values
------------------------------+--------------------
     Reporter:  debnet        |      Owner:  nobody
         Type:  Bug           |     Status:  new
    Component:  Core (Other)  |    Version:  1.9
     Severity:  Normal        |   Keywords:
 Triage Stage:  Unreviewed    |  Has patch:  0
Easy pickings:  0             |      UI/UX:  0
------------------------------+--------------------
 When using a QuerySet returning no values without a whole model behind,
 the Paginator fails to display data from page.

 '''Example OK:'''

 {{{
 queryset = Model.objects.filter(my_filter_return_nothing=value)
 paginator = Paginator(queryset, 10)
 list(paginator.page(1))
 >>> []
 }}}

 '''Example KO:'''

 {{{
 queryset =
 Model.objects.values('whatever_field').filter(my_filter_return_nothing=value)
 paginator = Paginator(queryset, 10)
 list(paginator.page(1))
 >>>
 ---------------------------------------------------------------------------
 AttributeError                            Traceback (most recent call
 last)
 <ipython-input-38-56e5635092e7> in <module>()
 ----> 1 list(paginator.page(1))

 \lib\site-packages\django\core\paginator.py in __len__(self)
     115
     116     def __len__(self):
 --> 117         return len(self.object_list)
     118
     119     def __getitem__(self, index):

 \lib\site-packages\django\db\models\query.py in __len__(self)
     238
     239     def __len__(self):
 --> 240         self._fetch_all()
     241         return len(self._result_cache)
     242

 \lib\site-packages\django\db\models\query.py in _fetch_all(self)
    1072     def _fetch_all(self):
    1073         if self._result_cache is None:
 -> 1074             self._result_cache = list(self.iterator())
    1075         if self._prefetch_related_lookups and not
 self._prefetch_done:
    1076             self._prefetch_related_objects()

 \lib\site-packages\django\db\models\query.py in __iter__(self)
     110         names = extra_names + field_names + annotation_names
     111
 --> 112         for row in compiler.results_iter():
     113             yield dict(zip(names, row))
     114

 \lib\site-packages\django\db\models\sql\compiler.py in results_iter(self,
 results)
     805         if results is None:
     806             results = self.execute_sql(MULTI)
 --> 807         fields = [s[0] for s in self.select[0:self.col_count]]
     808         converters = self.get_converters(fields)
     809         for rows in results:

 AttributeError: 'SQLCompiler' object has no attribute 'col_count'
 }}}

 Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/25894>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.24e12a8751cab46eb91b5ee0c7e1df68%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to