Django

Code

Ticket #6180 (closed: fixed)

Opened 5 months ago

Last modified 3 weeks ago

DateQuerySet fails with LIMIT (on psycopg2)

Reported by: anonymous Assigned to: nobody
Component: Database wrapper Version: SVN
Keywords: DateQuerySet dates psycopg2 qs-rf-fixed Cc: bp@barryp.org
Triage Stage: Accepted Has patch: 0
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

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]

Attachments

Change History

02/25/08 00:11:07 changed by Barry Pederson <bp@barryp.org>

  • cc set to bp@barryp.org.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

02/25/08 00:16:03 changed by mtredinnick

  • keywords changed from DateQuerySet dates psycopg2 to DateQuerySet dates psycopg2 qs-rf-fixed.
  • stage changed from Unreviewed to Accepted.

04/26/08 21:50:16 changed by mtredinnick

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

(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


Add/Change #6180 (DateQuerySet fails with LIMIT (on psycopg2))




Change Properties
Action