diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-01 16:48:16 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-04-01 16:48:16 +0000 |
| commit | f7cf58ac0ebf720e5c48f00e99c31cf39c4fca50 (patch) | |
| tree | 048de60757bde88fb24d035508559d78b851884d /django | |
| parent | c39ec6dccb389fbb4047e44f5247e18bb76ae598 (diff) | |
Fixed #12429 -- Ensure that raw queries call resolve_columns if the backend defines it. This ensures (as much as possible) that the model values returned by a raw query match that in normal queries. Thanks to Ian Kelly for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12904 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/query.py | 11 | ||||
| -rw-r--r-- | django/db/models/sql/compiler.py | 4 | ||||
| -rw-r--r-- | django/db/models/sql/query.py | 5 |
3 files changed, 14 insertions, 6 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py index d0b605db84..3567671a1a 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -1407,20 +1407,27 @@ class RawQuerySet(object): self._model_fields = {} for field in self.model._meta.fields: name, column = field.get_attname_column() - self._model_fields[converter(column)] = name + self._model_fields[converter(column)] = field return self._model_fields def transform_results(self, values): model_init_kwargs = {} annotations = () + # Perform database backend type resolution + connection = connections[self.db] + compiler = connection.ops.compiler('SQLCompiler')(self.query, connection, self.db) + if hasattr(compiler, 'resolve_columns'): + fields = [self.model_fields.get(c,None) for c in self.columns] + values = compiler.resolve_columns(values, fields) + # Associate fields to values for pos, value in enumerate(values): column = self.columns[pos] # Separate properties from annotations if column in self.model_fields.keys(): - model_init_kwargs[self.model_fields[column]] = value + model_init_kwargs[self.model_fields[column].attname] = value else: annotations += (column, value), diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index a07e506fc7..84c28a0d35 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -14,10 +14,6 @@ class SQLCompiler(object): self.using = using self.quote_cache = {} - # Check that the compiler will be able to execute the query - for alias, aggregate in self.query.aggregate_select.items(): - self.connection.ops.check_aggregate_support(aggregate) - def pre_sql_setup(self): """ Does any necessary class setup immediately prior to producing SQL. This diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 9819be09a1..72d4bc9c1b 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -189,6 +189,11 @@ class Query(object): raise ValueError("Need either using or connection") if using: connection = connections[using] + + # Check that the compiler will be able to execute the query + for alias, aggregate in self.aggregate_select.items(): + connection.ops.check_aggregate_support(aggregate) + return connection.ops.compiler(self.compiler)(self, connection, using) def get_meta(self): |
