﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19001	only+annotate+selected_related is broken	jiaji	nobody	"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

}}}
"	Bug	closed	Database layer (models, ORM)	1.4	Normal	needsinfo			Unreviewed	0	0	0	0	0	0
