Skip to content

Commit

Permalink
Merge pull request #17232 from mvdbeek/session_order_fix
Browse files Browse the repository at this point in the history
[23.1] Fix User.current_galaxy_session
  • Loading branch information
bgruening authored Dec 23, 2023
2 parents 1ffcf8e + 1113f4c commit 4d07aa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10761,7 +10761,9 @@ class CleanupEventImplicitlyConvertedDatasetAssociationAssociation(Base):
# See https://github.com/sqlalchemy/sqlalchemy/discussions/7638 for approach
session_partition = select(
GalaxySession,
func.row_number().over(order_by=GalaxySession.update_time, partition_by=GalaxySession.user_id).label("index"),
func.row_number()
.over(order_by=GalaxySession.update_time.desc(), partition_by=GalaxySession.user_id)
.label("index"),
).alias()
partitioned_session = aliased(GalaxySession, session_partition)
User.current_galaxy_session = relationship(
Expand Down
11 changes: 11 additions & 0 deletions test/unit/data/test_galaxy_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,17 @@ def _non_empty_flush(self):
session.add(lf)
session.flush()

def test_current_session(self):
user = model.User(email="[email protected]", password="password")
galaxy_session = model.GalaxySession()
galaxy_session.user = user
self.persist(user, galaxy_session)
assert user.current_galaxy_session == galaxy_session
new_galaxy_session = model.GalaxySession()
new_galaxy_session.user = user
self.persist(user, new_galaxy_session)
assert user.current_galaxy_session == new_galaxy_session

def test_flush_refreshes(self):
# Normally I don't believe in unit testing library code, but the behaviors around attribute
# states and flushing in SQL Alchemy is very subtle and it is good to have a executable
Expand Down

0 comments on commit 4d07aa9

Please sign in to comment.