Fix query without order by handling
This commit is contained in:
@@ -8,6 +8,7 @@ Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
|||||||
^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
- Made assert_* functions automatically rollback session
|
- Made assert_* functions automatically rollback session
|
||||||
|
- Changed make_order_by_deterministic attach order by primary key for queries without order by
|
||||||
- Fixed alias handling in has_unique_index
|
- Fixed alias handling in has_unique_index
|
||||||
- Fixed alias handling in has_index
|
- Fixed alias handling in has_index
|
||||||
- Fixed alias handling in make_order_by_deterministic
|
- Fixed alias handling in make_order_by_deterministic
|
||||||
|
@@ -169,9 +169,11 @@ def make_order_by_deterministic(query):
|
|||||||
|
|
||||||
.. versionadded: 0.27.1
|
.. versionadded: 0.27.1
|
||||||
"""
|
"""
|
||||||
if not query._order_by:
|
order_by_func = sa.asc
|
||||||
return query
|
|
||||||
|
|
||||||
|
if not query._order_by:
|
||||||
|
column = None
|
||||||
|
else:
|
||||||
order_by = query._order_by[0]
|
order_by = query._order_by[0]
|
||||||
if isinstance(order_by, sa.sql.expression.UnaryExpression):
|
if isinstance(order_by, sa.sql.expression.UnaryExpression):
|
||||||
if order_by.modifier == sa.sql.operators.desc_op:
|
if order_by.modifier == sa.sql.operators.desc_op:
|
||||||
@@ -181,7 +183,6 @@ def make_order_by_deterministic(query):
|
|||||||
column = order_by.get_children()[0]
|
column = order_by.get_children()[0]
|
||||||
else:
|
else:
|
||||||
column = order_by
|
column = order_by
|
||||||
order_by_func = sa.asc
|
|
||||||
|
|
||||||
# Queries that are ordered by an already
|
# Queries that are ordered by an already
|
||||||
if isinstance(column, sa.Column):
|
if isinstance(column, sa.Column):
|
||||||
|
@@ -82,7 +82,7 @@ class TestMakeOrderByDeterministic(TestCase):
|
|||||||
def test_query_without_order_by(self):
|
def test_query_without_order_by(self):
|
||||||
query = self.session.query(self.User)
|
query = self.session.query(self.User)
|
||||||
query = make_order_by_deterministic(query)
|
query = make_order_by_deterministic(query)
|
||||||
assert 'ORDER BY' not in str(query)
|
assert 'ORDER BY "user".id' in str(query)
|
||||||
|
|
||||||
def test_alias(self):
|
def test_alias(self):
|
||||||
alias = sa.orm.aliased(self.User.__table__)
|
alias = sa.orm.aliased(self.User.__table__)
|
||||||
|
Reference in New Issue
Block a user