From 59a655988ee95e4b4e4646cebea88b620d8fcdd2 Mon Sep 17 00:00:00 2001 From: Anssi Kääriäinen Date: Sun, 15 Jul 2012 14:41:05 +0300 Subject: Fixed #13844 -- Avoid converting unknown db values to float This patch removes an unconditional float(value) conversion from db backend default convert_values() method. This can cause problems when aggregating over character fields for example. In addition, Oracle and SQLite already return the bare value from their convert_values(). In the long term the converting should be done by fields, and the fields should then call database backend specific converters when needed. The current setup is inflexible for 3rd party fields. Thanks to Merlijn van Deen for the original patch. --- django/db/backends/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'django') diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 9606245162..9f64cfc5f0 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -878,19 +878,19 @@ class BaseDatabaseOperations(object): return self.year_lookup_bounds(value) def convert_values(self, value, field): - """Coerce the value returned by the database backend into a consistent type that - is compatible with the field type. + """ + Coerce the value returned by the database backend into a consistent type + that is compatible with the field type. """ internal_type = field.get_internal_type() if internal_type == 'DecimalField': return value - elif internal_type and internal_type.endswith('IntegerField') or internal_type == 'AutoField': + elif (internal_type and (internal_type.endswith('IntegerField') + or internal_type == 'AutoField')): return int(value) elif internal_type in ('DateField', 'DateTimeField', 'TimeField'): return value - # No field, or the field isn't known to be a decimal or integer - # Default to a float - return float(value) + return value def check_aggregate_support(self, aggregate_func): """Check that the backend supports the provided aggregate -- cgit v1.3