diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index b261a9b8337d..6b605fee2f17 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -6170,6 +6170,12 @@ def attribute_columns(column_collection, attributes, nesting_level=None): q = q.add_entity(entity) if entity == DatasetCollectionElement: q = q.filter(entity.id == dce.c.id) + + # Since we will apply DISTINCT, ensure all columns from the ORDER BY clause are explicitly selected + for col in order_by_columns: + if col not in q.statement._raw_columns: # do not select a column more than once. + q = q.add_column(col) + return q.distinct().order_by(*order_by_columns) @property