diff --git a/CHANGES.rst b/CHANGES.rst index 8b5eebb..16a428e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) diff --git a/sqlalchemy_utils/functions/sort_query.py b/sqlalchemy_utils/functions/sort_query.py index 15004f7..4bbc55c 100644 --- a/sqlalchemy_utils/functions/sort_query.py +++ b/sqlalchemy_utils/functions/sort_query.py @@ -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( diff --git a/tests/functions/test_make_order_by_deterministic.py b/tests/functions/test_make_order_by_deterministic.py index 4c3c08e..2663e48 100644 --- a/tests/functions/test_make_order_by_deterministic.py +++ b/tests/functions/test_make_order_by_deterministic.py @@ -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')