mirror of
https://github.com/django/django.git
synced 2025-08-29 15:04:38 +00:00
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:
parent
fd9398816e
commit
277ed07209
3 changed files with 11 additions and 3 deletions
|
@ -960,10 +960,13 @@ class Subquery(Expression):
|
|||
def __init__(self, queryset, output_field=None, **extra):
|
||||
self.queryset = queryset
|
||||
self.extra = extra
|
||||
if output_field is None and len(self.queryset.query.select) == 1:
|
||||
output_field = self.queryset.query.select[0].field
|
||||
super().__init__(output_field)
|
||||
|
||||
def _resolve_output_field(self):
|
||||
if len(self.queryset.query.select) == 1:
|
||||
return self.queryset.query.select[0].field
|
||||
return super()._resolve_output_field()
|
||||
|
||||
def copy(self):
|
||||
clone = super().copy()
|
||||
clone.queryset = clone.queryset.all()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue