Skip to content

Commit

Permalink
Fix SA Mutable (see details)
Browse files Browse the repository at this point in the history
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:
sqlalchemy/sqlalchemy#6018
sqlalchemy/sqlalchemy@1031fc6
  • Loading branch information
jdavcs committed Mar 26, 2021
1 parent 3854841 commit 636e27b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/galaxy/model/custom_types.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/model/database_utils.py
Expand Up @@ -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:
Expand Down

0 comments on commit 636e27b

Please sign in to comment.