From 636e27b006d54dc50c235f3d0e54e6d47c56a08d Mon Sep 17 00:00:00 2001 From: Sergey Golitsynskiy Date: Fri, 26 Mar 2021 01:13:58 -0400 Subject: [PATCH] Fix SA Mutable (see details) The ``sqlalchemy.ext.mutable`` extension now tracks the "parents" collection using the :class:`.InstanceState` associated with objects, rather than the object itself. (see Ref) This commit updates our implementation of these methods (required for SQLAlchemy>=1.4.2) Ref: https://github.com/sqlalchemy/sqlalchemy/discussions/6018 https://github.com/sqlalchemy/sqlalchemy/commit/1031fc6f781a3a6088467791e837f23a4b338aef# --- lib/galaxy/model/custom_types.py | 9 +++++---- lib/galaxy/model/database_utils.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/galaxy/model/custom_types.py b/lib/galaxy/model/custom_types.py index ca2062504e3e..0eb9618b1283 100644 --- a/lib/galaxy/model/custom_types.py +++ b/lib/galaxy/model/custom_types.py @@ -10,6 +10,7 @@ import numpy import sqlalchemy from sqlalchemy.ext.mutable import Mutable +from sqlalchemy.inspection import inspect from sqlalchemy.types import ( CHAR, LargeBinary, @@ -152,15 +153,15 @@ def load(state, *args): val = cls.coerce(key, val) state.dict[key] = val if isinstance(val, cls): - val._parents[state.obj()] = key + val._parents[state] = key def set(target, value, oldvalue, initiator): if not isinstance(value, cls): value = cls.coerce(key, value) if isinstance(value, cls): - value._parents[target.obj()] = key + value._parents[target] = key if isinstance(oldvalue, cls): - oldvalue._parents.pop(target.obj(), None) + oldvalue._parents.pop(inspect(target), None) return value def pickle(state, state_dict): @@ -173,7 +174,7 @@ def pickle(state, state_dict): def unpickle(state, state_dict): if 'ext.mutable.values' in state_dict: for val in state_dict['ext.mutable.values']: - val._parents[state.obj()] = key + val._parents[state] = key sqlalchemy.event.listen(parent_cls, 'load', load, raw=True, propagate=True) sqlalchemy.event.listen(parent_cls, 'refresh', load, raw=True, propagate=True) diff --git a/lib/galaxy/model/database_utils.py b/lib/galaxy/model/database_utils.py index c9193357e0aa..4baf6d6da4a0 100644 --- a/lib/galaxy/model/database_utils.py +++ b/lib/galaxy/model/database_utils.py @@ -60,7 +60,7 @@ class PosgresDatabaseManager(DatabaseManager): def _handle_no_database(self): self.database = self.url.database # use database from db_url - self.url = self.url.set(database = 'postgres') + self.url = self.url.set(database='postgres') def exists(self): with sqlalchemy_engine(self.url) as engine: