Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit 12a96bfa263d514884ef11009913b2f8bb163472 1 parent 72a6ac5
Anssi Kääriäinen authored December 16, 2012

Showing 1 changed file with 3 additions and 5 deletions. Show diff stats Hide diff stats

  1. 8  django/db/backends/__init__.py
8  django/db/backends/__init__.py
@@ -883,16 +883,14 @@ def convert_values(self, value, field):
883 883
         Coerce the value returned by the database backend into a consistent type
884 884
         that is compatible with the field type.
885 885
         """
886  
-        internal_type = field.get_internal_type()
887  
-        if internal_type == 'DecimalField':
  886
+        if value is None:
888 887
             return value
889  
-        elif internal_type == 'FloatField':
  888
+        internal_type = field.get_internal_type()
  889
+        if internal_type == 'FloatField':
890 890
             return float(value)
891 891
         elif (internal_type and (internal_type.endswith('IntegerField')
892 892
                                  or internal_type == 'AutoField')):
893 893
             return int(value)
894  
-        elif internal_type in ('DateField', 'DateTimeField', 'TimeField'):
895  
-            return value
896 894
         return value
897 895
 
898 896
     def check_aggregate_support(self, aggregate_func):

0 notes on commit 12a96bf

Please sign in to comment.
Something went wrong with that request. Please try again.