Skip to content

Commit

Permalink
Merge pull request #13498 from ic4f/dev_sa20_2
Browse files Browse the repository at this point in the history
More backref_cascade fixes (SQLAlchemy 2.0)
  • Loading branch information
mvdbeek authored Mar 9, 2022
2 parents ff72765 + f450876 commit cf0ff2e
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 18 deletions.
4 changes: 3 additions & 1 deletion lib/galaxy/authnz/custos_authnz.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CustosAuthnzToken,
User,
)
from galaxy.model.orm.util import add_object_to_object_session
from ..authnz import IdentityProvider

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -186,7 +187,6 @@ def create_user(self, token, trans, login_redirect_url):
trans.app.user_manager.send_activation_email(trans, email, username)

custos_authnz_token = CustosAuthnzToken(
user=user,
external_user_id=user_id,
provider=self.config["provider"],
access_token=access_token,
Expand All @@ -195,6 +195,8 @@ def create_user(self, token, trans, login_redirect_url):
expiration_time=expiration_time,
refresh_expiration_time=refresh_expiration_time,
)
add_object_to_object_session(custos_authnz_token, user)
custos_authnz_token.user = user

trans.sa_session.add(user)
trans.sa_session.add(custos_authnz_token)
Expand Down
23 changes: 23 additions & 0 deletions lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ def __init__(self, job, working_directory, prepare_files_cmd):
self.parameters = []
self.state = Task.states.NEW
self.working_directory = working_directory
add_object_to_object_session(self, job)
self.job = job
self.prepare_input_files_cmd = prepare_files_cmd
self._init_metrics()
Expand Down Expand Up @@ -1980,6 +1981,7 @@ class JobToInputLibraryDatasetAssociation(Base, RepresentById):

def __init__(self, name, dataset):
self.name = name
add_object_to_object_session(self, dataset)
self.dataset = dataset


Expand All @@ -1997,6 +1999,7 @@ class JobToOutputLibraryDatasetAssociation(Base, RepresentById):

def __init__(self, name, dataset):
self.name = name
add_object_to_object_session(self, dataset)
self.dataset = dataset


Expand Down Expand Up @@ -2140,6 +2143,7 @@ class JobExternalOutputMetadata(Base, RepresentById):
job = relationship("Job", back_populates="external_output_metadata")

def __init__(self, job=None, dataset=None):
add_object_to_object_session(self, job)
self.job = job
if isinstance(dataset, galaxy.model.HistoryDatasetAssociation):
self.history_dataset_association = dataset
Expand Down Expand Up @@ -2280,6 +2284,8 @@ class JobContainerAssociation(Base, RepresentById):
job = relationship("Job", back_populates="container")

def __init__(self, **kwd):
if "job" in kwd:
add_object_to_object_session(self, kwd["job"])
super().__init__(**kwd)
self.container_info = self.container_info or {}

Expand Down Expand Up @@ -2371,6 +2377,7 @@ class UserGroupAssociation(Base, RepresentById):
group = relationship("Group", back_populates="users")

def __init__(self, user, group):
add_object_to_object_session(self, user)
self.user = user
self.group = group

Expand Down Expand Up @@ -3052,6 +3059,7 @@ class UserQuotaAssociation(Base, Dictifiable, RepresentById):
dict_element_visible_keys = ["user"]

def __init__(self, user, quota):
add_object_to_object_session(self, user)
self.user = user
self.quota = quota

Expand All @@ -3070,6 +3078,7 @@ class GroupQuotaAssociation(Base, Dictifiable, RepresentById):
dict_element_visible_keys = ["group"]

def __init__(self, group, quota):
add_object_to_object_session(self, group)
self.group = group
self.quota = quota

Expand Down Expand Up @@ -3257,6 +3266,7 @@ class LibraryDatasetDatasetAssociationPermissions(Base, RepresentById):
def __init__(self, action, library_item, role):
self.action = action
if isinstance(library_item, LibraryDatasetDatasetAssociation):
add_object_to_object_session(self, library_item)
self.library_dataset_dataset_association = library_item
else:
raise Exception(f"Invalid LibraryDatasetDatasetAssociation specified: {library_item.__class__.__name__}")
Expand Down Expand Up @@ -3291,6 +3301,7 @@ class DefaultHistoryPermissions(Base, RepresentById):
role = relationship("Role")

def __init__(self, history, action, role):
add_object_to_object_session(self, history)
self.history = history
self.action = action
self.role = role
Expand Down Expand Up @@ -5392,6 +5403,7 @@ def __init__(
self, id=None, parent=None, dataset=None, file_type=None, deleted=False, purged=False, metadata_safe=True
):
self.id = id
add_object_to_object_session(self, dataset)
if isinstance(dataset, HistoryDatasetAssociation):
self.dataset = dataset
elif isinstance(dataset, LibraryDatasetDatasetAssociation):
Expand Down Expand Up @@ -6471,6 +6483,7 @@ class GalaxySessionToHistoryAssociation(Base, RepresentById):

def __init__(self, galaxy_session, history):
self.galaxy_session = galaxy_session
add_object_to_object_session(self, history)
self.history = history


Expand Down Expand Up @@ -6573,6 +6586,7 @@ def __init__(
workflow=None,
hidden=False,
):
add_object_to_object_session(self, user)
self.user = user
self.name = name
self.slug = slug
Expand Down Expand Up @@ -6891,6 +6905,7 @@ def add_connection(self, input_name, output_name, output_step, input_subworkflow
conn = WorkflowStepConnection()
conn.input_step_input = step_input
conn.output_name = output_name
add_object_to_object_session(conn, output_step)
conn.output_step = output_step
if input_subworkflow_step_index is not None:
input_subworkflow_step = self.subworkflow.step_by_index(input_subworkflow_step_index)
Expand Down Expand Up @@ -7059,6 +7074,7 @@ class WorkflowStepInput(Base, RepresentById):
)

def __init__(self, workflow_step):
add_object_to_object_session(self, workflow_step)
self.workflow_step = workflow_step
self.default_value_set = False

Expand Down Expand Up @@ -7247,6 +7263,7 @@ def attach_subworkflow_invocation_for_step(self, step, subworkflow_invocation):
assoc = WorkflowInvocationToSubworkflowInvocationAssociation()
assoc.workflow_invocation = self
assoc.workflow_step = step
add_object_to_object_session(subworkflow_invocation, self.history)
subworkflow_invocation.history = self.history
subworkflow_invocation.workflow = step.subworkflow
assoc.subworkflow_invocation = subworkflow_invocation
Expand Down Expand Up @@ -9026,6 +9043,7 @@ class HistoryDatasetAssociationRatingAssociation(ItemRatingAssociation, Represen
user = relationship("User")

def _set_item(self, history_dataset_association):
add_object_to_object_session(self, history_dataset_association)
self.history_dataset_association = history_dataset_association


Expand All @@ -9040,6 +9058,7 @@ class StoredWorkflowRatingAssociation(ItemRatingAssociation, RepresentById):
user = relationship("User")

def _set_item(self, stored_workflow):
add_object_to_object_session(self, stored_workflow)
self.stored_workflow = stored_workflow


Expand All @@ -9054,6 +9073,7 @@ class PageRatingAssociation(ItemRatingAssociation, RepresentById):
user = relationship("User")

def _set_item(self, page):
add_object_to_object_session(self, page)
self.page = page


Expand All @@ -9068,6 +9088,7 @@ class VisualizationRatingAssociation(ItemRatingAssociation, RepresentById):
user = relationship("User")

def _set_item(self, visualization):
add_object_to_object_session(self, visualization)
self.visualization = visualization


Expand All @@ -9082,6 +9103,7 @@ class HistoryDatasetCollectionRatingAssociation(ItemRatingAssociation, Represent
user = relationship("User")

def _set_item(self, dataset_collection):
add_object_to_object_session(self, dataset_collection)
self.dataset_collection = dataset_collection


Expand All @@ -9096,6 +9118,7 @@ class LibraryDatasetCollectionRatingAssociation(ItemRatingAssociation, Represent
user = relationship("User")

def _set_item(self, dataset_collection):
add_object_to_object_session(self, dataset_collection)
self.dataset_collection = dataset_collection


Expand Down
6 changes: 6 additions & 0 deletions lib/tool_shed/webapp/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
TrimmedString,
)
from galaxy.model.orm.now import now
from galaxy.model.orm.util import add_object_to_object_session
from galaxy.security.validate_user_input import validate_password_str
from galaxy.util import unique_id
from galaxy.util.bunch import Bunch
Expand Down Expand Up @@ -182,6 +183,7 @@ def __init__(self, user, token=None):
self.token = token
else:
self.token = unique_id()
add_object_to_object_session(self, user)
self.user = user
self.expiration_time = now() + timedelta(hours=24)

Expand Down Expand Up @@ -252,6 +254,7 @@ class UserGroupAssociation(Base, _HasTable):
group = relationship("Group", back_populates="users")

def __init__(self, user, group):
add_object_to_object_session(self, user)
self.user = user
self.group = group

Expand All @@ -268,7 +271,9 @@ class UserRoleAssociation(Base, _HasTable):
role = relationship("Role", back_populates="users")

def __init__(self, user, role):
add_object_to_object_session(self, user)
self.user = user
add_object_to_object_session(self, role)
self.role = role


Expand Down Expand Up @@ -300,6 +305,7 @@ class RepositoryRoleAssociation(Base, _HasTable):
role = relationship("Role", back_populates="repositories")

def __init__(self, repository, role):
add_object_to_object_session(self, repository)
self.repository = repository
self.role = role

Expand Down
2 changes: 2 additions & 0 deletions test/unit/app/tools/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import galaxy.model
from galaxy.app_unittest_utils import tools_support
from galaxy.model.orm.util import add_object_to_object_session
from galaxy.util.bunch import Bunch

BASE_REPEAT_TOOL_CONTENTS = """<tool id="test_tool" name="Test Tool">
Expand Down Expand Up @@ -126,6 +127,7 @@ def __add_dataset(self, id, state="ok"):
hda.dataset.state = "ok"

self.trans.sa_session.add(hda)
add_object_to_object_session(self.history, hda)
self.history.datasets.append(hda)
self.trans.sa_session.flush()
return hda
Expand Down
Loading

0 comments on commit cf0ff2e

Please sign in to comment.