diff --git a/lib/galaxy/managers/collections.py b/lib/galaxy/managers/collections.py index 70370edd4526..1cd673b50c08 100644 --- a/lib/galaxy/managers/collections.py +++ b/lib/galaxy/managers/collections.py @@ -829,7 +829,9 @@ def _get_collection_contents_qry(self, parent_id, limit=None, offset=None): DCE = model.DatasetCollectionElement qry = Query(DCE).filter(DCE.dataset_collection_id == parent_id) qry = qry.order_by(DCE.element_index) - qry = qry.options(joinedload("child_collection"), joinedload("hda")) + qry = qry.options( + joinedload(model.DatasetCollectionElement.child_collection), joinedload(model.DatasetCollectionElement.hda) + ) if limit is not None: qry = qry.limit(int(limit)) if offset is not None: diff --git a/lib/galaxy/managers/history_contents.py b/lib/galaxy/managers/history_contents.py index 055a8b94687b..077b8fff1fdf 100644 --- a/lib/galaxy/managers/history_contents.py +++ b/lib/galaxy/managers/history_contents.py @@ -438,7 +438,7 @@ def _contained_id_map(self, id_list): .query(component_class) .filter(component_class.id.in_(id_list)) .options(undefer(component_class._metadata)) - .options(joinedload("dataset.actions")) # TODO: use class attr after moving Dataset to declarative mapping. + .options(joinedload(component_class.dataset).joinedload(model.Dataset.actions)) .options(joinedload(component_class.tags)) .options(joinedload(component_class.annotations)) # type: ignore[attr-defined] ) diff --git a/lib/galaxy/managers/session.py b/lib/galaxy/managers/session.py index 5d9fc238af81..4f6ca157f0ec 100644 --- a/lib/galaxy/managers/session.py +++ b/lib/galaxy/managers/session.py @@ -30,7 +30,7 @@ def get_session_from_session_key(self, session_key: str): self.model.GalaxySession.table.c.is_valid == true(), ) ) - .options(joinedload("user")) + .options(joinedload(self.model.GalaxySession.user)) .first() ) return galaxy_session diff --git a/lib/galaxy/managers/sharable.py b/lib/galaxy/managers/sharable.py index aebef5bb039b..20eb3442f72d 100644 --- a/lib/galaxy/managers/sharable.py +++ b/lib/galaxy/managers/sharable.py @@ -222,7 +222,7 @@ def _query_shared_with(self, user, eagerloads=True, **kwargs): Return a query for this model already filtered to models shared with a particular user. """ - query = self.session().query(self.model_class).join("users_shared_with") + query = self.session().query(self.model_class).join(self.model_class.users_shared_with) if eagerloads is False: query = query.enable_eagerloads(False) # TODO: as filter in FilterParser also diff --git a/lib/galaxy/managers/workflows.py b/lib/galaxy/managers/workflows.py index b1fd01a565a5..9e2e011bf779 100644 --- a/lib/galaxy/managers/workflows.py +++ b/lib/galaxy/managers/workflows.py @@ -163,10 +163,10 @@ def index_query( query = query.outerjoin(model.StoredWorkflow.users_shared_with) query = query.outerjoin(model.StoredWorkflow.tags) - latest_workflow_load = joinedload("latest_workflow") + latest_workflow_load = joinedload(model.StoredWorkflow.latest_workflow) if not payload.skip_step_counts: latest_workflow_load = latest_workflow_load.undefer("step_count") - latest_workflow_load = latest_workflow_load.lazyload("steps") + latest_workflow_load = latest_workflow_load.lazyload(model.Workflow.steps) query = query.options(joinedload(model.StoredWorkflow.annotations)) query = query.options(latest_workflow_load) @@ -268,9 +268,11 @@ def get_stored_workflow(self, trans, workflow_id, by_stored_id=True) -> StoredWo ) ) stored_workflow = workflow_query.options( - joinedload("annotations"), - joinedload("tags"), - subqueryload("latest_workflow").joinedload("steps").joinedload("*"), + joinedload(trans.app.model.StoredWorkflow.annotations), + joinedload(trans.app.model.StoredWorkflow.tags), + subqueryload(trans.app.model.StoredWorkflow.latest_workflow) + .joinedload(trans.app.model.Workflow.steps) + .joinedload("*"), ).first() if stored_workflow is None: if not by_stored_id: @@ -366,10 +368,10 @@ def get_invocation(self, trans, decoded_invocation_id, eager=False) -> model.Wor if eager: q = q.options( subqueryload(model.WorkflowInvocation.steps) - .joinedload("implicit_collection_jobs") - .joinedload("jobs") - .joinedload("job") - .joinedload("input_datasets") + .joinedload(model.WorkflowInvocationStep.implicit_collection_jobs) + .joinedload(model.ImplicitCollectionJobs.jobs) + .joinedload(model.ImplicitCollectionJobsJobAssociation.job) + .joinedload(model.Job.input_datasets) ) workflow_invocation = q.get(decoded_invocation_id) if not workflow_invocation: diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 29af9c116d7e..bda53e4dc969 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -2962,10 +2962,10 @@ def active_dataset_and_roles_query(self): .filter(not_(HistoryDatasetAssociation.deleted)) .order_by(HistoryDatasetAssociation.table.c.hid.asc()) .options( - joinedload("dataset"), - joinedload("dataset.actions"), - joinedload("dataset.actions.role"), - joinedload("tags"), + joinedload(HistoryDatasetAssociation.dataset) + .joinedload(Dataset.actions) + .joinedload(DatasetPermissions.role), + joinedload(HistoryDatasetAssociation.tags), ) ) @@ -2993,7 +2993,10 @@ def active_visible_dataset_collections(self): .filter(not_(HistoryDatasetCollectionAssociation.deleted)) .filter(HistoryDatasetCollectionAssociation.visible) .order_by(HistoryDatasetCollectionAssociation.table.c.hid.asc()) - .options(joinedload("collection"), joinedload("tags")) + .options( + joinedload(HistoryDatasetCollectionAssociation.collection), + joinedload(HistoryDatasetCollectionAssociation.tags), + ) ) self._active_visible_dataset_collections = query.all() return self._active_visible_dataset_collections diff --git a/lib/galaxy/model/security.py b/lib/galaxy/model/security.py index 29159b70d0e9..881e3276bf47 100644 --- a/lib/galaxy/model/security.py +++ b/lib/galaxy/model/security.py @@ -1507,12 +1507,15 @@ def check_folder_contents(self, user, roles, folder, hidden_folder_ids=""): return True, "" action = self.permitted_actions.DATASET_ACCESS + raise lddas = ( self.sa_session.query(self.model.LibraryDatasetDatasetAssociation) .join("library_dataset") .filter(self.model.LibraryDataset.folder == folder) .join("dataset") - .options(joinedload("dataset").joinedload("actions")) + .options( + joinedload(self.model.LibraryDatasetDatasetAssociation.dataset).joinedload(self.model.Dataset.actions) + ) .all() ) diff --git a/lib/galaxy/tools/actions/upload_common.py b/lib/galaxy/tools/actions/upload_common.py index 94f752c8faf7..412e83d0b548 100644 --- a/lib/galaxy/tools/actions/upload_common.py +++ b/lib/galaxy/tools/actions/upload_common.py @@ -422,10 +422,11 @@ def active_folders(trans, folder): # Stolen from galaxy.web.controllers.library_common (importing from which causes a circular issues). # Much faster way of retrieving all active sub-folders within a given folder than the # performance of the mapper. This query also eagerloads the permissions on each folder. + raise return ( trans.sa_session.query(LibraryFolder) .filter_by(parent=folder, deleted=False) - .options(joinedload("actions")) + .options(joinedload(LibraryFolder.actions)) .order_by(LibraryFolder.table.c.name) .all() ) diff --git a/lib/galaxy/webapps/galaxy/controllers/history.py b/lib/galaxy/webapps/galaxy/controllers/history.py index 73d9717e7e0a..6411a3a158b6 100644 --- a/lib/galaxy/webapps/galaxy/controllers/history.py +++ b/lib/galaxy/webapps/galaxy/controllers/history.py @@ -208,7 +208,7 @@ def get_value(self, trans, grid, history): ] def build_initial_query(self, trans, **kwargs): - return trans.sa_session.query(self.model_class).join("users_shared_with") + return trans.sa_session.query(self.model_class).join(self.model_class.users_shared_with) def apply_query_filter(self, trans, query, **kwargs): return query.filter(model.HistoryUserShareAssociation.user == trans.user) diff --git a/lib/galaxy/webapps/galaxy/controllers/page.py b/lib/galaxy/webapps/galaxy/controllers/page.py index 180d782dea9d..b753e1a0786d 100644 --- a/lib/galaxy/webapps/galaxy/controllers/page.py +++ b/lib/galaxy/webapps/galaxy/controllers/page.py @@ -161,7 +161,11 @@ def build_initial_query(self, trans, **kwargs): trans.sa_session.query(self.model_class) .join("user") .filter(model.User.deleted == false()) - .options(joinedload("user").load_only("username"), joinedload("annotations"), undefer("average_rating")) + .options( + joinedload(self.model_class.user).load_only("username"), + joinedload(self.model_class.annotations), + undefer("average_rating"), + ) ) def apply_query_filter(self, trans, query, **kwargs): diff --git a/lib/galaxy/webapps/galaxy/controllers/visualization.py b/lib/galaxy/webapps/galaxy/controllers/visualization.py index e56b249d8a68..248b777ef90c 100644 --- a/lib/galaxy/webapps/galaxy/controllers/visualization.py +++ b/lib/galaxy/webapps/galaxy/controllers/visualization.py @@ -287,8 +287,12 @@ def build_initial_query(self, trans, **kwargs): # See optimization description comments and TODO for tags in matching public histories query. return ( trans.sa_session.query(self.model_class) - .join("user") - .options(joinedload("user").load_only("username"), joinedload("annotations"), undefer("average_rating")) + .join(self.model_class.user) + .options( + joinedload(self.model_class.user).load_only("username"), + joinedload(self.model_class.annotations), + undefer("average_rating"), + ) ) def apply_query_filter(self, trans, query, **kwargs): diff --git a/lib/galaxy/webapps/galaxy/controllers/workflow.py b/lib/galaxy/webapps/galaxy/controllers/workflow.py index 3e51a7d83082..8c8038c6384f 100644 --- a/lib/galaxy/webapps/galaxy/controllers/workflow.py +++ b/lib/galaxy/webapps/galaxy/controllers/workflow.py @@ -163,12 +163,12 @@ def build_initial_query(self, trans, **kwargs): # of its steps to be eagerly loaded. return ( trans.sa_session.query(self.model_class) - .join("user") + .join(self.model_class.user) .options( - lazyload("latest_workflow"), - joinedload("user").load_only("username"), - joinedload("annotations"), - undefer("average_rating"), + lazyload(self.model_class.latest_workflow), + joinedload(self.model_class.user).load_only(model.User.username), + joinedload(self.model_class.annotations), + undefer(self.model_class.average_rating), ) ) @@ -487,7 +487,7 @@ def editor(self, trans, id=None, workflow_id=None, version=None): trans.sa_session.query(model.StoredWorkflow) .filter_by(user=trans.user, deleted=False, hidden=False) .order_by(desc(model.StoredWorkflow.table.c.update_time)) - .options(joinedload("latest_workflow").joinedload("steps")) + .options(joinedload(model.StoredWorkflow.latest_workflow).joinedload(model.Workflow.steps)) .all() ) if version is None: diff --git a/lib/galaxy/webapps/reports/controllers/system.py b/lib/galaxy/webapps/reports/controllers/system.py index 0c8bfbe63ee3..e26446c75d2d 100644 --- a/lib/galaxy/webapps/reports/controllers/system.py +++ b/lib/galaxy/webapps/reports/controllers/system.py @@ -115,7 +115,7 @@ def deleted_histories(self, trans, **kwd): model.History.update_time < cutoff_time, ) ) - .options(joinedload("datasets")) + .options(joinedload(model.History.datasets)) ) for history in histories: diff --git a/lib/tool_shed/webapp/api/repositories.py b/lib/tool_shed/webapp/api/repositories.py index 5dfc86d2ecf0..86f6a9f859e0 100644 --- a/lib/tool_shed/webapp/api/repositories.py +++ b/lib/tool_shed/webapp/api/repositories.py @@ -50,6 +50,7 @@ repository_util, tool_util, ) +from tool_shed.webapp import model from tool_shed.webapp.search.repo_search import RepoSearch log = logging.getLogger(__name__) @@ -118,7 +119,7 @@ def get_ordered_installable_revisions(self, trans, name=None, owner=None, **kwd) if owner is None: owner = kwd.get("owner", None) tsr_id = kwd.get("tsr_id", None) - eagerload_columns = ["downloadable_revisions"] + eagerload_columns = [model.Repository.downloadable_revisions] if None not in [name, owner]: # Get the repository information. repository = repository_util.get_repository_by_name_and_owner( @@ -217,7 +218,7 @@ def get_repository_revision_install_info(self, trans, name, owner, changeset_rev if name and owner and changeset_revision: # Get the repository information. repository = repository_util.get_repository_by_name_and_owner( - self.app, name, owner, eagerload_columns=["downloadable_revisions"] + self.app, name, owner, eagerload_columns=[model.Repository.downloadable_revisions] ) if repository is None: log.debug(f"Cannot locate repository {name} owned by {owner}") @@ -284,7 +285,7 @@ def get_installable_revisions(self, trans, **kwd): tsr_id = kwd.get("tsr_id", None) if tsr_id is not None: repository = repository_util.get_repository_in_tool_shed( - self.app, tsr_id, eagerload_columns=["downloadable_revisions"] + self.app, tsr_id, eagerload_columns=[model.Repository.downloadable_revisions] ) else: error_message = "Error in the Tool Shed repositories API in get_ordered_installable_revisions: " @@ -737,7 +738,7 @@ def updates(self, trans, **kwd): changeset_revision = kwd.get("changeset_revision", None) hexlify_this = util.asbool(kwd.get("hexlify", True)) repository = repository_util.get_repository_by_name_and_owner( - trans.app, name, owner, eagerload_columns=["downloadable_revisions"] + trans.app, name, owner, eagerload_columns=[model.Repository.downloadable_revisions] ) if repository and repository.downloadable_revisions: repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision( @@ -837,7 +838,7 @@ def metadata(self, trans, id, **kwd): downloadable_only = util.asbool(kwd.get("downloadable_only", "True")) all_metadata = {} repository = repository_util.get_repository_in_tool_shed( - self.app, id, eagerload_columns=["downloadable_revisions"] + self.app, id, eagerload_columns=[model.Repository.downloadable_revisions] ) for changeset, changehash in metadata_util.get_metadata_revisions( self.app, repository, sort_revisions=True, downloadable=downloadable_only