Skip to content

Commit

Permalink
Fix union operation (see note)
Browse files Browse the repository at this point in the history
Can't call union() more than once because on second call we have a
CompoundSelect. Reversing stmt with all-stmts will result in improper
nesting. Proposed fix solves this: we collect Select statements into a
list, then union the first item with the rest. The list is guaranteed to
have at least one item.
  • Loading branch information
jdavcs committed Oct 20, 2023
1 parent 0d5da07 commit 0d4ab60
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/galaxy/managers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,14 @@ def tags_used(self, user, tag_models=None):
return []

# create a union of select statements for each tag model for this user - getting only the tname and user_value
all_tags_stmt = None
all_stmts = []
for tag_model in tag_models:
stmt = select(tag_model.user_tname, tag_model.user_value).where(tag_model.user == user)
all_tags_stmt = stmt if all_tags_stmt is None else stmt.union(all_tags_stmt.union)
all_stmts.append(stmt)
union_stmt = all_stmts[0].union(*all_stmts[1:]) # union the first select with the rest

# boil the tag tuples down into a sorted list of DISTINCT name:val strings
all_tags_stmt = all_tags_stmt.distinct()
tag_tuples = self.session().exectute(all_tags_stmt)
tag_tuples = self.session().execute(union_stmt) # no need for DISTINCT: union is a set operation.
tags = [(f"{name}:{val}" if val else name) for name, val in tag_tuples]
# consider named tags while sorting
return sorted(tags, key=lambda str: re.sub("^name:", "#", str))
Expand Down

0 comments on commit 0d4ab60

Please sign in to comment.