Fixed #29195 -- Fixed Exists.output_field resolution on single-valued queries.

The Subquery class which Exists inherits from defaulted to using single-valued
querie's field if no output_field was explicitly specified on initialization
which was bypassing the Exists.output_field defined at the class level.

Moving Subquery's dynamic output_field resolution to _resolve_output_field
should make sure the fallback logic is only performed if required.

Regression in 08654a99bb.

Thanks Oli Warner for the detailed report.
This commit is contained in:
Simon Charette 2018-03-08 02:06:19 -05:00 committed by Tim Graham
parent fd9398816e
commit 277ed07209
3 changed files with 11 additions and 3 deletions

View file

@ -417,6 +417,10 @@ class BasicExpressionsTests(TestCase):
outer = Employee.objects.annotate(is_point_of_contact=Exists(inner))
self.assertIs(outer.exists(), True)
def test_exist_single_field_output_field(self):
queryset = Company.objects.values('pk')
self.assertIsInstance(Exists(queryset).output_field, models.BooleanField)
def test_subquery(self):
Company.objects.filter(name='Example Inc.').update(
point_of_contact=Employee.objects.get(firstname='Joe', lastname='Smith'),