Fix ambiguous column sorting

This commit is contained in:
Konsta Vesterinen
2014-09-09 08:57:10 +03:00
parent 5522c2be65
commit 208137e5d6
2 changed files with 11 additions and 3 deletions

View File

@@ -508,10 +508,11 @@ def get_all_descriptors(expr):
insp = sa.inspect(expr)
polymorphic_mappers = get_polymorphic_mappers(insp)
if polymorphic_mappers:
attrs = {}
attrs = dict(get_mapper(expr).all_orm_descriptors)
for submapper in polymorphic_mappers:
attrs.update(submapper.all_orm_descriptors)
for key, descriptor in submapper.all_orm_descriptors.items():
if key not in attrs:
attrs[key] = descriptor
return attrs
return get_mapper(expr).all_orm_descriptors

View File

@@ -273,6 +273,13 @@ class TestSortQueryWithPolymorphicInheritance(TestCase):
)
assert_contains('ORDER BY article.category ASC', query)
def test_with_ambiguous_column(self):
query = sort_query(
self.session.query(self.TextItem),
'id'
)
assert_contains('ORDER BY text_item.id ASC', query)
class TestSortQueryWithCustomPolymorphic(TestCase):
"""