diff options
| author | sharonwoo <29156885+sharonwoo@users.noreply.github.com> | 2024-09-27 09:17:07 +0800 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-30 12:48:45 +0000 |
| commit | cbb0812683cf3236e4a4003bf7f74b119d3cde0c (patch) | |
| tree | 0ce9060d94f357f25d79e12cc951a9449490b500 /tests | |
| parent | 12b9ef38b3ff7f5b8b24a5f42e8923fdb6db44bb (diff) | |
Fixed #35235 -- Removed caching of BaseExpression._output_field_or_none.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/expressions/tests.py | 11 | ||||
| -rw-r--r-- | tests/postgres_tests/test_aggregates.py | 16 |
2 files changed, 27 insertions, 0 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index af4cf01fca..d36107b358 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -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), diff --git a/tests/postgres_tests/test_aggregates.py b/tests/postgres_tests/test_aggregates.py index 885512cfca..ddd3b6bbd0 100644 --- a/tests/postgres_tests/test_aggregates.py +++ b/tests/postgres_tests/test_aggregates.py @@ -334,6 +334,22 @@ class TestGeneralAggregate(PostgreSQLTestCase): ) self.assertCountEqual(qs, [[], [5]]) + def test_array_agg_with_empty_filter_and_default_values(self): + for filter_value in ([-1], []): + for default_value in ([], Value([])): + with self.subTest(filter=filter_value, default=default_value): + queryset = AggregateTestModel.objects.annotate( + test_array_agg=ArrayAgg( + "stattestmodel__int1", + filter=Q(pk__in=filter_value), + default=default_value, + ) + ) + self.assertSequenceEqual( + queryset.values_list("test_array_agg", flat=True), + [[], [], [], []], + ) + def test_bit_and_general(self): values = AggregateTestModel.objects.filter(integer_field__in=[0, 1]).aggregate( bitand=BitAnd("integer_field") |
