Fixed #35235 -- Removed caching of BaseExpression._output_field_or_none.

This commit is contained in:
sharonwoo 2024-09-27 09:17:07 +08:00 committed by Sarah Boyce
parent 12b9ef38b3
commit cbb0812683
3 changed files with 37 additions and 7 deletions

View file

@ -51,6 +51,7 @@ from django.db.models.expressions import (
Combinable,
CombinedExpression,
NegatedExpression,
OutputFieldIsNoneError,
RawSQL,
Ref,
)
@ -2329,6 +2330,16 @@ class ValueTests(TestCase):
time = Time.objects.annotate(one=Value(1, output_field=DecimalField())).first()
self.assertEqual(time.one, 1)
def test_output_field_is_none_error(self):
with self.assertRaises(OutputFieldIsNoneError):
Employee.objects.annotate(custom_expression=Value(None)).first()
def test_output_field_or_none_property_not_cached(self):
expression = Value(None, output_field=None)
self.assertIsNone(expression._output_field_or_none)
expression.output_field = BooleanField()
self.assertIsInstance(expression._output_field_or_none, BooleanField)
def test_resolve_output_field(self):
value_types = [
("str", CharField),