1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #24615 -- ordering by expression not part of SELECT

Fixed queries where an expression was used in order_by() but the
expression wasn't in the query's select clause (for example the
expression could be masked by .values() call)

Thanks to Trac alias MattBlack85 for the report.
This commit is contained in:
Anssi Kääriäinen
2015-04-15 08:46:19 +03:00
committed by Claude Paroz
parent bcf700b4e3
commit fb5c7748da
5 changed files with 25 additions and 1 deletions

View File

@@ -12,5 +12,8 @@ class WKTAdapter(object):
return False
return self.wkt == other.wkt and self.srid == other.srid
def __hash__(self):
return hash((self.wkt, self.srid))
def __str__(self):
return self.wkt

View File

@@ -28,6 +28,9 @@ class PostGISAdapter(object):
return False
return (self.ewkb == other.ewkb) and (self.srid == other.srid)
def __hash__(self):
return hash((self.ewkb, self.srid))
def __str__(self):
return self.getquoted()

View File

@@ -262,10 +262,17 @@ class SQLCompiler(object):
descending = True if order == 'DESC' else False
if col in self.query.annotation_select:
# Reference to expression in SELECT clause
order_by.append((
OrderBy(Ref(col, self.query.annotation_select[col]), descending=descending),
True))
continue
if col in self.query.annotations:
# References to an expression which is masked out of the SELECT clause
order_by.append((
OrderBy(self.query.annotations[col], descending=descending),
False))
continue
if '.' in field:
# This came in through an extra(order_by=...) addition. Pass it