Fix make_order_by_deterministic alias handling
This commit is contained in:
@@ -8,8 +8,9 @@ Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Made assert_* functions automatically rollback session
|
||||
- Fix alias handling in has_unique_index
|
||||
- Fix alias handling in has_index
|
||||
- Fixed alias handling in has_unique_index
|
||||
- Fixed alias handling in has_index
|
||||
- Fixed alias handling in make_order_by_deterministic
|
||||
|
||||
|
||||
0.27.4 (2014-10-23)
|
||||
|
@@ -184,8 +184,12 @@ def make_order_by_deterministic(query):
|
||||
order_by_func = sa.asc
|
||||
|
||||
# Queries that are ordered by an already
|
||||
if isinstance(column, sa.Column) and has_unique_index(column):
|
||||
return query
|
||||
if isinstance(column, sa.Column):
|
||||
try:
|
||||
if has_unique_index(column):
|
||||
return query
|
||||
except TypeError:
|
||||
return query
|
||||
|
||||
base_table = get_tables(query._entities[0])[0]
|
||||
query = query.order_by(
|
||||
|
@@ -83,3 +83,9 @@ class TestMakeOrderByDeterministic(TestCase):
|
||||
query = self.session.query(self.User)
|
||||
query = make_order_by_deterministic(query)
|
||||
assert 'ORDER BY' not in str(query)
|
||||
|
||||
def test_alias(self):
|
||||
alias = sa.orm.aliased(self.User.__table__)
|
||||
query = self.session.query(alias).order_by(alias.c.name)
|
||||
query = make_order_by_deterministic(query)
|
||||
assert str(query).endswith('ORDER BY user_1.name')
|
||||
|
Reference in New Issue
Block a user