diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 057349776a98..f2bac5f47e96 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 @@ -9542,7 +9543,7 @@ def store(cls, server_url, association): @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):