Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25998 closed Bug (duplicate)

SQLCompiler error when using Paginator + values(...) when query returns no data — at Version 2

Reported by: Andrew Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Normal Keywords: SQLCompiler, Paginator, values
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Andrew)

I am experiencing a crash in the SQLCompiler when I try to execute a paginated query after calling .values(...).

AttributeError: 'SQLCompiler' object has no attribute 'col_count'
  • Postgres 9.3, psycopg2==2.6.1
  • Django 1.9
  • No data is present in the table
# Query must have NO data returned for it
qs = Room.objects.values('id')
pg = Paginator(per_page=1, object_list=qs)
res = list(pg.page(1))

class Room(models.Model):
    has_tv = models.BooleanField()
======================================================================
ERROR: test_pure_django (api.tests.test_api_call.TestApiCall)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/andrew/dev/st/abc/api/tests/test_api_call.py", line 25, in test_pure_django
    res = list(pg.page(1))
  File "/Users/andrew/dev/st/abc/venv/bin/../lib/python2.7/_abcoll.py", line 602, in __iter__
    v = self[i]
  File "/Users/andrew/dev/st/abc/venv/lib/python2.7/site-packages/django/core/paginator.py", line 125, in __getitem__
    self.object_list = list(self.object_list)
  File "/Users/andrew/dev/st/abc/venv/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__
    self._fetch_all()
  File "/Users/andrew/dev/st/abc/venv/lib/python2.7/site-packages/django/db/models/query.py", line 1074, in _fetch_all
    self._result_cache = list(self.iterator())
  File "/Users/andrew/dev/st/abc/venv/lib/python2.7/site-packages/django/db/models/query.py", line 112, in __iter__
    for row in compiler.results_iter():
  File "/Users/andrew/dev/st/abc/venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 807, in results_iter
    fields = [s[0] for s in self.select[0:self.col_count]]
AttributeError: 'SQLCompiler' object has no attribute 'col_count'

I have a fairly minimal reproduction, and can try to reduce it even further (removing DRF, psycopg2, etc) if needed. I don't think it's an issue with postgres. I think it has something to do with the ValuesIterable, but have no way of telling for sure.

Change History (2)

comment:1 by Tim Graham, 9 years ago

Resolution: duplicate
Status: newclosed
Type: UncategorizedBug

This looks like a duplicate of #25894 which will be fixed in the upcoming 1.9.1 release. Can you verify the issue is fixed for you on the stable/1.9.x branch and reopen if not? Thanks.

comment:2 by Andrew, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top