summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-12-16 22:24:15 +0200
committerAnssi Kääriäinen <akaariai@gmail.com>2012-12-16 23:26:16 +0200
commit12a96bfa263d514884ef11009913b2f8bb163472 (patch)
treef14bcdc87fe03d187ddd730ea3558d964b2dc03c
parent72a6ac568d28afdfa5be6bcb01526adb03eedfae (diff)
Fixed #19197 -- fixed convert_values() for nullable numeric fields
Cleaned up the implementation of base convert_values() a little, and made sure it accepts None as a value for numeric fields. There are no tests attached. The reason is that not all of the convert_values() accept None as a value for numeric fields (for example sqlite3.convert_values()). The reason the base convert_values() needs to accept None is that this situation might arise in custom compilers for 3rd party backends. It is easy to keep the convert_values() working, so lets do that.
-rw-r--r--django/db/backends/__init__.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 4390b1ec04..5116f50668 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -883,16 +883,14 @@ class BaseDatabaseOperations(object):
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':
+ if value is None:
return value
- elif internal_type == 'FloatField':
+ internal_type = field.get_internal_type()
+ if internal_type == 'FloatField':
return float(value)
elif (internal_type and (internal_type.endswith('IntegerField')
or internal_type == 'AutoField')):
return int(value)
- elif internal_type in ('DateField', 'DateTimeField', 'TimeField'):
- return value
return value
def check_aggregate_support(self, aggregate_func):