Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20587 -- Made convert_values handle None values

  • Loading branch information...
commit 680b512fc1509ca05cf56fada30f6b833735362a 1 parent ef37b23
Gil Gonçalves authored June 22, 2013
3  django/db/backends/sqlite3/base.py
@@ -250,6 +250,9 @@ def convert_values(self, value, field):
250 250
         and gets dates and datetimes wrong.
251 251
         For consistency with other backends, coerce when required.
252 252
         """
  253
+        if value is None:
  254
+            return None
  255
+
253 256
         internal_type = field.get_internal_type()
254 257
         if internal_type == 'DecimalField':
255 258
             return util.typecast_decimal(field.format_number(value))
37  tests/backends/tests.py
@@ -11,9 +11,12 @@
11 11
 from django.db import (connection, connections, DEFAULT_DB_ALIAS,
12 12
     DatabaseError, IntegrityError, transaction)
13 13
 from django.db.backends.signals import connection_created
  14
+from django.db.backends.sqlite3.base import DatabaseOperations
14 15
 from django.db.backends.postgresql_psycopg2 import version as pg_version
15 16
 from django.db.backends.util import format_number
16 17
 from django.db.models import Sum, Avg, Variance, StdDev
  18
+from django.db.models.fields import (AutoField, DateField, DateTimeField,
  19
+    DecimalField, IntegerField, TimeField)
17 20
 from django.db.utils import ConnectionHandler
18 21
 from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
19 22
     TransactionTestCase)
@@ -402,7 +405,7 @@ class EscapingChecksDebug(EscapingChecks):
402 405
     pass
403 406
 
404 407
 
405  
-class SqlliteAggregationTests(TestCase):
  408
+class SqliteAggregationTests(TestCase):
406 409
     """
407 410
     #19360: Raise NotImplementedError when aggregating on date/time fields.
408 411
     """
@@ -418,6 +421,38 @@ def test_aggregation(self):
418 421
                 models.Item.objects.all().aggregate, aggregate('last_modified'))
419 422
 
420 423
 
  424
+class SqliteChecks(TestCase):
  425
+
  426
+    @unittest.skipUnless(connection.vendor == 'sqlite',
  427
+                         "No need to do SQLite checks")
  428
+    def test_convert_values_to_handle_null_value(self):
  429
+        database_operations = DatabaseOperations(connection)
  430
+        self.assertEqual(
  431
+            None,
  432
+            database_operations.convert_values(None, AutoField(primary_key=True))
  433
+        )
  434
+        self.assertEqual(
  435
+            None,
  436
+            database_operations.convert_values(None, DateField())
  437
+        )
  438
+        self.assertEqual(
  439
+            None,
  440
+            database_operations.convert_values(None, DateTimeField())
  441
+        )
  442
+        self.assertEqual(
  443
+            None,
  444
+            database_operations.convert_values(None, DecimalField())
  445
+        )
  446
+        self.assertEqual(
  447
+            None,
  448
+            database_operations.convert_values(None, IntegerField())
  449
+        )
  450
+        self.assertEqual(
  451
+            None,
  452
+            database_operations.convert_values(None, TimeField())
  453
+        )
  454
+
  455
+
421 456
 class BackendTestCase(TestCase):
422 457
 
423 458
     def create_squares_with_executemany(self, args):

0 notes on commit 680b512

Claude Paroz

Not a big deal, but FYI there is an `assertIsNone assertion available in unittest.

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