Skip to content

Commit

Permalink
Explicitly select all columns that appear in order_by
Browse files Browse the repository at this point in the history
Ref: https://docs.sqlalchemy.org/en/20/changelog/migration_20.html#using-distinct-with-additional-columns-but-only-select-the-entity
Note: this query-building code needs to be converted to SA 2.0; but same
requirement applies.
  • Loading branch information
jdavcs committed Oct 26, 2023
1 parent 9e33c77 commit 71f7ae7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 71f7ae7

Please sign in to comment.