From c2904121248431a2795621e9edd6b5e85b9c4d89 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Tue, 19 Mar 2024 23:49:18 -0400 Subject: [PATCH 1/3] Fix creation and association of new histories w/ brand new single/remote user --- lib/galaxy/webapps/base/webapp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index c3c1dd8bbcf2..824abb45cbeb 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -936,8 +936,8 @@ def get_or_create_default_history(self): if default_history: history = default_history self.set_history(history) - else: - history = self.new_history() + else: + history = self.new_history() return history From 1fdbb121dcfe21027fd08d07b3e27736c3a50663 Mon Sep 17 00:00:00 2001 From: Marius van den Beek Date: Wed, 20 Mar 2024 08:06:41 +0100 Subject: [PATCH 2/3] Create new history if user has no history AND for anonymous users --- lib/galaxy/webapps/base/webapp.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index 824abb45cbeb..cd897139c4c7 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -938,6 +938,8 @@ def get_or_create_default_history(self): self.set_history(history) else: history = self.new_history() + else: + history = self.new_history() return history From e3805c7bfb7b164b0b1c73aea0e391b919cbe4cb Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Wed, 20 Mar 2024 07:58:42 -0400 Subject: [PATCH 3/3] Refactoring for clarity. --- lib/galaxy/webapps/base/webapp.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/galaxy/webapps/base/webapp.py b/lib/galaxy/webapps/base/webapp.py index cd897139c4c7..b9430a3774c0 100644 --- a/lib/galaxy/webapps/base/webapp.py +++ b/lib/galaxy/webapps/base/webapp.py @@ -912,36 +912,28 @@ def get_or_create_default_history(self): Gets or creates a default history and associates it with the current session. """ + + # Just return the current history if one exists and is not deleted. history = self.galaxy_session.current_history if history and not history.deleted: return history + # Look for an existing history that has the default name, is not + # deleted, and is empty. If this exists, we associate it with the + # current session and return it. user = self.galaxy_session.user if user: - # Look for default history that (a) has default name + is not deleted and - # (b) has no datasets. If suitable history found, use it; otherwise, create - # new history. stmt = select(self.app.model.History).filter_by( user=user, name=self.app.model.History.default_name, deleted=False ) unnamed_histories = self.sa_session.scalars(stmt) - default_history = None for history in unnamed_histories: if history.empty: - # Found suitable default history. - default_history = history - break - - # Set or create history. - if default_history: - history = default_history - self.set_history(history) - else: - history = self.new_history() - else: - history = self.new_history() + self.set_history(history) + return history - return history + # No suitable history found, create a new one. + return self.new_history() def get_most_recent_history(self): """