From 6c06a9ed719c9db7628c860c244681a46f73b415 Mon Sep 17 00:00:00 2001 From: John Davis Date: Mon, 2 Oct 2023 13:30:31 -0400 Subject: [PATCH] Fix SA2.0 usage in model.PSAAssociation --- lib/galaxy/model/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 23d9fadad313..ad0cfd1b8fdf 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -61,6 +61,7 @@ Column, column, DateTime, + delete, desc, event, false, @@ -9273,7 +9274,8 @@ def save(self): @classmethod def store(cls, server_url, association): try: - assoc = cls.sa_session.query(cls).filter_by(server_url=server_url, handle=association.handle)[0] + 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) assoc.secret = base64.encodebytes(association.secret).decode() @@ -9286,11 +9288,17 @@ def store(cls, server_url, association): @classmethod def get(cls, *args, **kwargs): - return cls.sa_session.query(cls).filter_by(*args, **kwargs) + stmt = select(PSAAssociation).filter_by(*args, **kwargs) + return cls.sa_session.scalars(stmt) @classmethod def remove(cls, ids_to_delete): - cls.sa_session.query(cls).filter(cls.id.in_(ids_to_delete)).delete(synchronize_session="fetch") + stmt = ( + delete(PSAAssociation) + .where(PSAAssociation.id.in_(ids_to_delete)) + .execution_options(synchronize_session="fetch") + ) + PSAAssociation.sa_session.execute(stmt) class PSACode(Base, CodeMixin, RepresentById):