Fix User.current_galaxy_session

This commit is contained in:
mvdbeek
2023-12-23 10:34:11 +01:00
parent 1ffcf8e334
commit 1113f4c744
2 changed files with 14 additions and 1 deletions
+3 -1
View File
@@ -10761,7 +10761,9 @@ User.preferences = association_proxy("_preferences", "value", creator=UserPrefer
# 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(
+11
View File
@@ -698,6 +698,17 @@ class TestMappings(BaseModelTestCase):
session.add(lf)
session.flush()
def test_current_session(self):
user = model.User(email="testworkflows@bx.psu.edu", 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