Fixed sort_query hybrid property handling
This commit is contained in:
@@ -20,6 +20,15 @@ def sort_expression(expr, attr_name):
|
||||
return getattr(expr, attr_name)
|
||||
|
||||
|
||||
def get_entity(expr):
|
||||
if isinstance(expr, AliasedInsp):
|
||||
return expr.mapper.class_
|
||||
elif isinstance(expr, Mapper):
|
||||
return expr.class_
|
||||
else:
|
||||
return expr
|
||||
|
||||
|
||||
def matches_entity(alias, entity):
|
||||
if not alias:
|
||||
return True
|
||||
@@ -85,6 +94,7 @@ class QuerySorter(object):
|
||||
))
|
||||
|
||||
# Check hybrid properties.
|
||||
entity = get_entity(entity)
|
||||
if hasattr(entity, sort['attr']):
|
||||
return self.query.order_by(
|
||||
sort['func'](getattr(entity, sort['attr']))
|
||||
|
@@ -129,5 +129,4 @@ class TestSortQuery(TestCase):
|
||||
)
|
||||
)
|
||||
query = sort_query(query, '-category-articles_count')
|
||||
print query
|
||||
#assert 'ORDER BY (SELECT count(article.id) AS count_1' in str(query)
|
||||
assert 'ORDER BY (SELECT count(article.id) AS count_1' in str(query)
|
||||
|
Reference in New Issue
Block a user