From 3c6fb7efa4a44f99d660df660fd9eeea2bf7dbda Mon Sep 17 00:00:00 2001 From: John Davis Date: Tue, 20 Feb 2024 14:10:14 -0500 Subject: [PATCH 1/2] Fix bug: create new object if not in db --- lib/galaxy/model/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 057349776a98..e891b8ed8d1b 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -9526,11 +9526,12 @@ def save(self): @classmethod def store(cls, server_url, association): - try: + def get_or_create(): stmt = select(PSAAssociation).filter_by(server_url=server_url, handle=association.handle).limit(1) assoc = cls.sa_session.scalars(stmt).first() - except IndexError: - assoc = cls(server_url=server_url, handle=association.handle) + return assoc or cls(server_url=server_url, handle=association.handle) + + assoc = get_or_create() assoc.secret = base64.encodebytes(association.secret).decode() assoc.issued = association.issued assoc.lifetime = association.lifetime From fe93fd8c6e059f3321a8a913d64c2c75ccd4b707 Mon Sep 17 00:00:00 2001 From: John Davis Date: Wed, 21 Feb 2024 23:27:09 -0500 Subject: [PATCH 2/2] Return value must be subscriptable --- lib/galaxy/model/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index e891b8ed8d1b..f2bac5f47e96 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -9543,7 +9543,7 @@ def get_or_create(): @classmethod def get(cls, *args, **kwargs): stmt = select(PSAAssociation).filter_by(*args, **kwargs) - return cls.sa_session.scalars(stmt) + return cls.sa_session.scalars(stmt).all() @classmethod def remove(cls, ids_to_delete):