Opened 16 years ago

Closed 16 years ago

#6180 closed (fixed)

DateQuerySet fails with LIMIT (on psycopg2)

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords: DateQuerySet dates psycopg2 qs-rf-fixed
Cc: bp@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

DateQuerySets fail when limiting, the set needs to be resolved before accessing any single object.

This fails:

Order.objects.dates('created_at', 'month')[0]

with:

<class 'psycopg2.ProgrammingError'>       Traceback (most recent call last)

/home/hukka/dev/tarjontajakysynta/<ipython console> in <module>()

/usr/lib/python2.5/site-packages/django/db/models/query.py in __getitem__(self, k)
    155             else:
    156                 try:
--> 157                     return list(self._clone(_offset=k, _limit=1))[0]
    158                 except self.model.DoesNotExist, e:
    159                     raise IndexError, e.args

/usr/lib/python2.5/site-packages/django/db/models/query.py in __iter__(self)
    112 
    113     def __iter__(self):
--> 114         return iter(self._get_data())
    115 
    116     def __getitem__(self, k):

/usr/lib/python2.5/site-packages/django/db/models/query.py in _get_data(self)
    480     def _get_data(self):
    481         if self._result_cache is None:
--> 482             self._result_cache = list(self.iterator())
    483         return self._result_cache
    484 

/usr/lib/python2.5/site-packages/django/db/models/query.py in iterator(self)
    661             qn(self._field.column))), sql, group_by, self._order)
    662         cursor = connection.cursor()
--> 663         cursor.execute(sql, params)
    664 
    665         has_resolve_columns = hasattr(self, 'resolve_columns')

/usr/lib/python2.5/site-packages/django/db/backends/util.py in execute(self, sql, params)
     16         start = time()
     17         try:
---> 18             return self.cursor.execute(sql, params)
     19         finally:
     20             stop = time()

<class 'psycopg2.ProgrammingError'>: syntax error at or near "GROUP"
LINE 1: ...r"."created_at")  FROM "companies_order" LIMIT 1  GROUP BY 1...

This works:

list(Order.objects.dates('created_at', 'month'))[0]

Change History (3)

comment:1 by Barry Pederson <bp@…>, 16 years ago

Cc: bp@… added

comment:2 by Malcolm Tredinnick, 16 years ago

Keywords: qs-rf-fixed added
Triage Stage: UnreviewedAccepted

comment:3 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing
code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658

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