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:
committed by
Claude Paroz
parent
bcf700b4e3
commit
fb5c7748da
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user