Opened 12 years ago

Closed 12 years ago

#19001 closed Bug (needsinfo)

only+annotate+selected_related is broken

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

Description

The following code

qs = Beat.objects.only('id', 'place').filter(upload_time__gt=now()-timedelta(days=7)).annotate(nhearts=Count('hearts')).order_by('nhearts').select_related('place')
len(qs)

triggers the following error:

UnicodeEncodeError                        Traceback (most recent call last)
/home/jiaji/pythonenv/current/local/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 len(qs)

/home/jiaji/pythonenv/current/local/lib/python2.7/site-packages/django/db/models/query.pyc in __len__(self)
     83                 self._result_cache = list(self._iter)
     84             else:
---> 85                 self._result_cache = list(self.iterator())
     86         elif self._iter:
     87             self._result_cache.extend(self._iter)

/home/jiaji/pythonenv/current/local/lib/python2.7/site-packages/django/db/models/query.pyc in iterator(self)
    289             klass_info = get_klass_info(model, max_depth=max_depth,
    290                                         requested=requested, only_load=only_load)
--> 291         for row in compiler.results_iter():
    292             if fill_cache:
    293                 obj, _ = get_cached_row(row, index_start, db, klass_info,

/home/jiaji/pythonenv/current/local/lib/python2.7/site-packages/django/db/models/sql/compiler.pyc in results_iter(self)
    788                         for (alias, aggregate), value
    789                         in zip(self.query.aggregate_select.items(), row[aggregate_start:aggregate_end])
--> 790                     ]) + tuple(row[aggregate_end:])
    791 
    792                 yield row

/home/jiaji/pythonenv/current/local/lib/python2.7/site-packages/django/db/models/sql/query.pyc in resolve_aggregate(self, value, aggregate, connection)
    330         elif aggregate.is_ordinal:
    331             # Any ordinal aggregate (e.g., count) returns an int
--> 332             return int(value)
    333         elif aggregate.is_computed:
    334             # Any computed aggregate (e.g., avg) returns a float

UnicodeEncodeError: 'decimal' codec can't encode character u'\u53f7' in position 3: invalid decimal Unicode string

Change History (3)

comment:1 by anonymous, 12 years ago

I fogot to mention that it's in 1.4.1

comment:2 by Anssi Kääriäinen, 12 years ago

Without the model definition it is going to be somewhat laborious to reproduce this.

So, could you provide the models?

comment:3 by Aymeric Augustin, 12 years ago

Resolution: needsinfo
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top