Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1295 from LuRsT/fix_sqlite_convert_values_20587

Fixed #20587 -- Made convert_values handle None values
  • Loading branch information...
commit 864613c7e08ad6a5bc1737a5c21c711bd0385663 2 parents 257a137 + 680b512
@andrewgodwin andrewgodwin 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())
+ )
+
+
class BackendTestCase(TestCase):
def create_squares_with_executemany(self, args):
Please sign in to comment.
Something went wrong with that request. Please try again.