Django

Code

Ticket #7323 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

QuerySetPaginator on a QuerySet with values() throws an AssertionError on multiple columns

Reported by: farhan@thebitguru.com Assigned to: nobody
Milestone: 1.0 Component: Core framework
Version: SVN Keywords: qsrf-cleanup
Cc: farhan@thebitguru.com Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I have a simple QuerySetPaginator? where I am using a QuerySet? with values() as the source. This used to work before queryset-refactor branch was merged, but now has stopped working.

In [1]: from thebitguru.nodes.models import *

In [2]: from django.core.paginator import QuerySetPaginator

In [3]: queryset = ContentNode.objects.values("id","title")

In [4]: paginator = QuerySetPaginator(queryset, 10)

In [5]: page = paginator.page(1)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)

/storage/important/Development/django/thebitguru/<ipython console> in <module>()

/storage/important/Development/django/packages/django_temp_trunk/django/core/paginator.py in page(self, number)
     27     def page(self, number):
     28         "Returns a Page object for the given 1-based page number."
---> 29         number = self.validate_number(number)
     30         bottom = (number - 1) * self.per_page
     31         top = bottom + self.per_page

/storage/important/Development/django/packages/django_temp_trunk/django/core/paginator.py in validate_number(self, number)
     18         if number < 1:
     19             raise InvalidPage('That page number is less than 1')
---> 20         if number > self.num_pages:
     21             if number == 1 and self.allow_empty_first_page:
     22                 pass

/storage/important/Development/django/packages/django_temp_trunk/django/core/paginator.py in _get_num_pages(self)
     44         "Returns the total number of pages."
     45         if self._num_pages is None:
---> 46             hits = self.count - 1 - self.orphans
     47             if hits < 1:
     48                 hits = 0

/storage/important/Development/django/packages/django_temp_trunk/django/core/paginator.py in _get_count(self)
     68     def _get_count(self):
     69         if self._count is None:
---> 70             self._count = self.object_list.count()
     71         return self._count
     72     count = property(_get_count)

/storage/important/Development/django/packages/django_temp_trunk/django/db/models/query.py in count(self)
    182             return len(self._result_cache)
    183
--> 184         return self.query.get_count()
    185
    186     def get(self, *args, **kwargs):

/storage/important/Development/django/packages/django_temp_trunk/django/db/models/sql/query.py in get_count(self)
    220             obj.select = []
    221             obj.extra_select = {}
--> 222         obj.add_count_column()
    223         data = obj.execute_sql(SINGLE)
    224         if not data:

/storage/important/Development/django/packages/django_temp_trunk/django/db/models/sql/query.py in add_count_column(self)
   1343             else:
   1344                 assert len(self.select) == 1, \
-> 1345                         "Cannot add count col with multiple cols in 'select': %r" % self.select
   1346                 select = Count(self.select[0])
   1347         else:

AssertionError: Cannot add count col with multiple cols in 'select': [('nodes_contentnode', 'id'), ('nodes_contentnode', 'title')]

I found a similar report at: http://groups.google.com.au/group/django-users/browse_thread/thread/b39cd188847c4f94

Attachments

Change History

06/10/08 09:31:45 changed by gav

  • keywords set to qsrf-cleanup.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

06/16/08 12:10:45 changed by jacob

  • milestone set to 1.0.

06/29/08 06:50:05 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [7787]) Fixed #7323 -- Fixed a count() edge-case.


Add/Change #7323 (QuerySetPaginator on a QuerySet with values() throws an AssertionError on multiple columns)




Change Properties
Action