Fixed #29118 -- Fixed crash with QuerySet.order_by(Exists(...)).

This commit is contained in:
Raphael Gaschignard 2018-02-07 12:09:43 +09:00 committed by Tim Graham
parent 1a1264f149
commit bf26f66029
3 changed files with 14 additions and 6 deletions

View file

@ -1041,11 +1041,11 @@ class Exists(Subquery):
def __invert__(self):
return type(self)(self.queryset, negated=(not self.negated), **self.extra)
def resolve_expression(self, query=None, **kwargs):
def resolve_expression(self, query=None, *args, **kwargs):
# As a performance optimization, remove ordering since EXISTS doesn't
# care about it, just whether or not a row matches.
self.queryset = self.queryset.order_by()
return super().resolve_expression(query, **kwargs)
return super().resolve_expression(query, *args, **kwargs)
def as_sql(self, compiler, connection, template=None, **extra_context):
sql, params = super().as_sql(compiler, connection, template, **extra_context)