#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: | no | UI/UX: | no |
Description
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. Profile.profilekeyword_set.select_related().filter(approved=True).extra(select=select).annotate(anchors=Count('keyword__anchor')).select_related()
.... /usr/lib/python2.5/pprint.pyc in _safe_repr(object, context, maxlevels, level) 290 return format % _commajoin(components), readable, recursive 291 --> 292 rep = repr(object) 293 return rep, (rep and not rep.startswith('<')), False 294 /usr/lib/python2.5/site-packages/django/db/models/query.pyc in __repr__(self) 66 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) 85 /usr/lib/python2.5/site-packages/django/db/models/query.pyc in iterator(self) 236 model_cls = deferred_class_factory(self.model, skip) 237 --> 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) 2370 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 by , 15 years ago
comment:2 by , 15 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
comment:3 by , 12 years ago
Component: | ORM aggregation → Database layer (models, ORM) |
---|
Note:
See TracTickets
for help on using tickets.
Duplicate of #11104. Please search trac before filing a new ticket.