Merge pull request #1295 from LuRsT/fix_sqlite_convert_values_20587
Fixed #20587 -- Made convert_values handle None values
This commit is contained in:
commit
864613c7e0
|
@ -250,6 +250,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
and gets dates and datetimes wrong.
|
and gets dates and datetimes wrong.
|
||||||
For consistency with other backends, coerce when required.
|
For consistency with other backends, coerce when required.
|
||||||
"""
|
"""
|
||||||
|
if value is None:
|
||||||
|
return None
|
||||||
|
|
||||||
internal_type = field.get_internal_type()
|
internal_type = field.get_internal_type()
|
||||||
if internal_type == 'DecimalField':
|
if internal_type == 'DecimalField':
|
||||||
return util.typecast_decimal(field.format_number(value))
|
return util.typecast_decimal(field.format_number(value))
|
||||||
|
|
|
@ -11,9 +11,12 @@ from django.core.management.color import no_style
|
||||||
from django.db import (connection, connections, DEFAULT_DB_ALIAS,
|
from django.db import (connection, connections, DEFAULT_DB_ALIAS,
|
||||||
DatabaseError, IntegrityError, transaction)
|
DatabaseError, IntegrityError, transaction)
|
||||||
from django.db.backends.signals import connection_created
|
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.postgresql_psycopg2 import version as pg_version
|
||||||
from django.db.backends.util import format_number
|
from django.db.backends.util import format_number
|
||||||
from django.db.models import Sum, Avg, Variance, StdDev
|
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.db.utils import ConnectionHandler
|
||||||
from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
|
from django.test import (TestCase, skipUnlessDBFeature, skipIfDBFeature,
|
||||||
TransactionTestCase)
|
TransactionTestCase)
|
||||||
|
@ -402,7 +405,7 @@ class EscapingChecksDebug(EscapingChecks):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SqlliteAggregationTests(TestCase):
|
class SqliteAggregationTests(TestCase):
|
||||||
"""
|
"""
|
||||||
#19360: Raise NotImplementedError when aggregating on date/time fields.
|
#19360: Raise NotImplementedError when aggregating on date/time fields.
|
||||||
"""
|
"""
|
||||||
|
@ -418,6 +421,38 @@ class SqlliteAggregationTests(TestCase):
|
||||||
models.Item.objects.all().aggregate, aggregate('last_modified'))
|
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):
|
class BackendTestCase(TestCase):
|
||||||
|
|
||||||
def create_squares_with_executemany(self, args):
|
def create_squares_with_executemany(self, args):
|
||||||
|
|
Loading…
Reference in New Issue