summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/backends/__init__.py12
-rw-r--r--tests/regressiontests/aggregation_regress/tests.py12
2 files changed, 18 insertions, 6 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 9606245162..9f64cfc5f0 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -878,19 +878,19 @@ class BaseDatabaseOperations(object):
return self.year_lookup_bounds(value)
def convert_values(self, value, field):
- """Coerce the value returned by the database backend into a consistent type that
- is compatible with the field type.
+ """
+ Coerce the value returned by the database backend into a consistent type
+ that is compatible with the field type.
"""
internal_type = field.get_internal_type()
if internal_type == 'DecimalField':
return value
- elif internal_type and internal_type.endswith('IntegerField') or internal_type == 'AutoField':
+ elif (internal_type and (internal_type.endswith('IntegerField')
+ or internal_type == 'AutoField')):
return int(value)
elif internal_type in ('DateField', 'DateTimeField', 'TimeField'):
return value
- # No field, or the field isn't known to be a decimal or integer
- # Default to a float
- return float(value)
+ return value
def check_aggregate_support(self, aggregate_func):
"""Check that the backend supports the provided aggregate
diff --git a/tests/regressiontests/aggregation_regress/tests.py b/tests/regressiontests/aggregation_regress/tests.py
index e24eb43b87..b9f3ab27eb 100644
--- a/tests/regressiontests/aggregation_regress/tests.py
+++ b/tests/regressiontests/aggregation_regress/tests.py
@@ -866,3 +866,15 @@ class AggregationTests(TestCase):
['Peter Norvig'],
lambda b: b.name
)
+
+ def test_type_conversion(self):
+ # The database backend convert_values function should not try to covert
+ # CharFields to float. Refs #13844.
+ from django.db.models import CharField
+ from django.db import connection
+ testData = 'not_a_float_value'
+ testField = CharField()
+ self.assertEqual(
+ connection.ops.convert_values(testData, testField),
+ testData
+ )