Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#7323 closed (fixed)

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

Reported by: farhan@… Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: qsrf-cleanup
Cc: farhan@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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

Change History (4)

comment:1 by George Vilches, 16 years ago

Keywords: qsrf-cleanup added

comment:2 by Jacob, 16 years ago

milestone: 1.0

comment:3 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

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

comment:4 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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