Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #20587 -- Made convert_values handle None values

  • Loading branch information...
commit 680b512fc1509ca05cf56fada30f6b833735362a 1 parent ef37b23
@LuRsT LuRsT authored
Showing with 39 additions and 1 deletion.
  1. +3 −0  django/db/backends/sqlite3/base.py
  2. +36 −1 tests/backends/tests.py
View
3  django/db/backends/sqlite3/base.py
@@ -250,6 +250,9 @@ def convert_values(self, value, field):
and gets dates and datetimes wrong.
For consistency with other backends, coerce when required.
"""
+ if value is None:
+ return None
+
internal_type = field.get_internal_type()
if internal_type == 'DecimalField':
return util.typecast_decimal(field.format_number(value))
View
37 tests/backends/tests.py
@@ -11,9 +11,12 @@
from django.db import (connection, connections, DEFAULT_DB_ALIAS,
DatabaseError, IntegrityError, transaction)
from django.db.backends.signals import connection_created
+from django.db.backends.sqlite3.base import DatabaseOperations
from django.db.backends.postgresql_psycopg2 import version as pg_version
from django.db.backends.util import format_number
from django.db.models import Sum, Avg, Variance, StdDev
+from django.db.models.fields import (AutoField, DateField, DateTimeField,
+ DecimalField, IntegerField, TimeField)
from django.db.utils import ConnectionHandler
from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
TransactionTestCase)
@@ -402,7 +405,7 @@ class EscapingChecksDebug(EscapingChecks):
pass
-class SqlliteAggregationTests(TestCase):
+class SqliteAggregationTests(TestCase):
"""
#19360: Raise NotImplementedError when aggregating on date/time fields.
"""
@@ -418,6 +421,38 @@ def test_aggregation(self):
models.Item.objects.all().aggregate, aggregate('last_modified'))
+class SqliteChecks(TestCase):
+
+ @unittest.skipUnless(connection.vendor == 'sqlite',
+ "No need to do SQLite checks")
+ def test_convert_values_to_handle_null_value(self):
+ database_operations = DatabaseOperations(connection)
+ self.assertEqual(
+ None,
+ database_operations.convert_values(None, AutoField(primary_key=True))
+ )
+ self.assertEqual(
+ None,
+ database_operations.convert_values(None, DateField())
+ )
+ self.assertEqual(
+ None,
+ database_operations.convert_values(None, DateTimeField())
+ )
+ self.assertEqual(
+ None,
+ database_operations.convert_values(None, DecimalField())
+ )
+ self.assertEqual(
+ None,
+ database_operations.convert_values(None, IntegerField())
+ )
+ self.assertEqual(
+ None,
+ database_operations.convert_values(None, TimeField())
+ )
+
+
@claudep Collaborator
claudep added a note

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
class BackendTestCase(TestCase):
def create_squares_with_executemany(self, args):
@claudep

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.