From ed0cc52dc3b0dfebba8a38c12b6157a007309900 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Sun, 28 Mar 2021 13:06:29 +0200 Subject: [PATCH] Fixed #32585 -- Fixed Value() crash with DecimalField on SQLite. --- django/db/models/expressions.py | 2 +- tests/expressions/tests.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index e5291ab8d3..bdd23617ac 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -707,7 +707,7 @@ class Func(SQLiteNumericMixin, Expression): return copy -class Value(Expression): +class Value(SQLiteNumericMixin, Expression): """Represent a wrapped value as a node within an expression.""" # Provide a default value for `for_save` in order to allow unresolved # instances to be compiled until a decision is taken in #25425. diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index eb1bfdc2be..9b88c94d7b 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -1757,6 +1757,11 @@ class ValueTests(TestCase): value = Value('foo', output_field=CharField()) self.assertEqual(value.as_sql(compiler, connection), ('%s', ['foo'])) + def test_output_field_decimalfield(self): + Time.objects.create() + time = Time.objects.annotate(one=Value(1, output_field=DecimalField())).first() + self.assertEqual(time.one, 1) + def test_resolve_output_field(self): value_types = [ ('str', CharField),