From 59a655988ee95e4b4e4646cebea88b620d8fcdd2 Mon Sep 17 00:00:00 2001 From: Anssi Kääriäinen Date: Sun, 15 Jul 2012 14:41:05 +0300 Subject: Fixed #13844 -- Avoid converting unknown db values to float This patch removes an unconditional float(value) conversion from db backend default convert_values() method. This can cause problems when aggregating over character fields for example. In addition, Oracle and SQLite already return the bare value from their convert_values(). In the long term the converting should be done by fields, and the fields should then call database backend specific converters when needed. The current setup is inflexible for 3rd party fields. Thanks to Merlijn van Deen for the original patch. --- tests/regressiontests/aggregation_regress/tests.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') 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 + ) -- cgit v1.3