Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#11962 closed (duplicate)

Annotate with "extra" triggers Traceback (bad SQL)

Reported by: ErikW Owned by:
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords: annotate, extra
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I have a query which performs a fairly complex "extra query" (about 10 sub-select queries). When I added the annotate() call to the chain, I started getting the following traceback.

#select is a dict of SELECTS.
/usr/lib/python2.5/pprint.pyc in _safe_repr(object, context, maxlevels, level)
    290         return format % _commajoin(components), readable, recursive
--> 292     rep = repr(object)
    293     return rep, (rep and not rep.startswith('<')), False

/usr/lib/python2.5/site-packages/django/db/models/query.pyc in __repr__(self)
     67     def __repr__(self):
---> 68         data = list(self[:REPR_OUTPUT_SIZE + 1])
     69         if len(data) > REPR_OUTPUT_SIZE:
     70             data[-1] = "...(remaining elements truncated)..."

/usr/lib/python2.5/site-packages/django/db/models/query.pyc in __len__(self)
     81                 self._result_cache = list(self.iterator())
     82         elif self._iter:
---> 83             self._result_cache.extend(list(self._iter))
     84         return len(self._result_cache)

/usr/lib/python2.5/site-packages/django/db/models/query.pyc in iterator(self)
    236             model_cls = deferred_class_factory(self.model, skip)
--> 238         for row in self.query.results_iter():
    239             if fill_cache:
    240                 obj, _ = get_cached_row(self.model, row,

/usr/lib/python2.5/site-packages/django/db/models/sql/query.pyc in results_iter(self)
    285         resolve_columns = hasattr(self, 'resolve_columns')
    286         fields = None
--> 287         for rows in self.execute_sql(MULTI):
    288             for row in rows:
    289                 if resolve_columns:

/usr/lib/python2.5/site-packages/django/db/models/sql/query.pyc in execute_sql(self, result_type)
   2367                 return
   2368         cursor = self.connection.cursor()
-> 2369         cursor.execute(sql, params)
   2371         if not result_type:

ProgrammingError: syntax error at or near "SELECT"
LINE 1: ...keyword"."keyword", "keywords_keyword"."created", SELECT sea...

It looks like a comma is being added after "keywords_keyword"."created" instead of a ")" (just a guess).

Change History (3)

comment:1 Changed 8 years ago by Alex Gaynor

Duplicate of #11104. Please search trac before filing a new ticket.

comment:2 Changed 8 years ago by Alex Gaynor

Resolution: duplicate
Status: newclosed

comment:3 Changed 5 years ago by Anssi Kääriäinen

Component: ORM aggregationDatabase layer (models, ORM)
Note: See TracTickets for help on using tickets.
Back to Top