From 208dcb9196466af1db363d4b307391d5ad36e042 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 19 Jan 2018 13:39:31 +0100 Subject: [PATCH 1/4] Stop walking up to parent HDA --- lib/galaxy/webapps/galaxy/controllers/dataset.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/webapps/galaxy/controllers/dataset.py b/lib/galaxy/webapps/galaxy/controllers/dataset.py index c21cee44b9a..6b1b009aaad 100644 --- a/lib/galaxy/webapps/galaxy/controllers/dataset.py +++ b/lib/galaxy/webapps/galaxy/controllers/dataset.py @@ -936,17 +936,13 @@ class DatasetInterface(BaseUIController, UsesAnnotations, UsesItemRatings, UsesE # Invalid HDA assert hda, 'Invalid history dataset ID' - # Walk up parent datasets to find the containing history - topmost_parent = hda - while topmost_parent.parent: - topmost_parent = topmost_parent.parent # If the user is anonymous, make sure the HDA is owned by the current session. if not user: current_history_id = trans.galaxy_session.current_history_id - assert topmost_parent.history.id == current_history_id, 'Data does not belong to current user' + assert hda.history.id == current_history_id, 'Data does not belong to current user' # If the user is known, make sure the HDA is owned by the current user. else: - assert topmost_parent.history.user == user, 'Data does not belong to current user' + assert hda.history.user == user, 'Data does not belong to current user' # Ensure HDA is deleted hda.deleted = True From ca51898bc4038fc93fa53a5a2fa9367ab8db6b8b Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 19 Jan 2018 14:50:08 +0100 Subject: [PATCH 2/4] Fix cleanup datasets script --- scripts/cleanup_datasets/cleanup_datasets.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/cleanup_datasets/cleanup_datasets.py b/scripts/cleanup_datasets/cleanup_datasets.py index 105fe3d1a59..c299a639da1 100755 --- a/scripts/cleanup_datasets/cleanup_datasets.py +++ b/scripts/cleanup_datasets/cleanup_datasets.py @@ -19,6 +19,7 @@ sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pa import galaxy.config import galaxy.model.mapping +from galaxy.datatypes import registry from galaxy.exceptions import ObjectNotFound from galaxy.objectstore import build_object_store_from_config from galaxy.util import unicodify @@ -340,7 +341,7 @@ def delete_datasets(app, cutoff_time, remove_from_disk, info_only=False, force_r deleted_dataset_count += 1 for dataset_instance in dataset.history_associations + dataset.library_associations: # Mark each associated HDA as deleted - _purge_dataset_instance(dataset_instance, app, remove_from_disk, include_children=True, info_only=info_only, is_deletable=True) + _purge_dataset_instance(dataset_instance, app, remove_from_disk, info_only=info_only, is_deletable=True) deleted_instance_count += 1 stop = time.time() print("Examined %d datasets, marked %d datasets and %d dataset instances (HDA) as deleted" % (len(skip), deleted_dataset_count, deleted_instance_count)) @@ -381,13 +382,13 @@ def purge_datasets(app, cutoff_time, remove_from_disk, info_only=False, force_re print("##########################################") -def _purge_dataset_instance(dataset_instance, app, remove_from_disk, include_children=True, info_only=False, is_deletable=False): +def _purge_dataset_instance(dataset_instance, app, remove_from_disk, info_only=False, is_deletable=False): # A dataset_instance is either a HDA or an LDDA. Purging a dataset instance marks the instance as deleted, # and marks the associated dataset as deleted if it is not associated with another active DatsetInstance. if not info_only: print("Marking as deleted: %s id %d (for dataset id %d)" % (dataset_instance.__class__.__name__, dataset_instance.id, dataset_instance.dataset.id)) - dataset_instance.mark_deleted(include_children=include_children) + dataset_instance.mark_deleted() dataset_instance.clear_associated_files() app.sa_session.add(dataset_instance) app.sa_session.flush() @@ -403,10 +404,6 @@ def _purge_dataset_instance(dataset_instance, app, remove_from_disk, include_chi print("Not deleting dataset ", dataset_instance.dataset.id, " (will be possibly deleted without 'info_only' mode)") else: print("Not deleting dataset %d (shared between multiple histories/libraries, at least one not deleted)" % dataset_instance.dataset.id) - # need to purge children here - if include_children: - for child in dataset_instance.children: - _purge_dataset_instance(child, app, remove_from_disk, include_children=include_children, info_only=info_only) def _dataset_is_deletable(dataset): @@ -530,6 +527,9 @@ class CleanupDatasetsApplication(object): self.object_store = build_object_store_from_config(config) # Setup the database engine and ORM self.model = galaxy.model.mapping.init(config.file_path, config.database_connection, engine_options={}, create_tables=False, object_store=self.object_store) + r = registry.Registry() + r.load_datatypes() + galaxy.model.set_datatypes_registry(r) @property def sa_session(self): From 654ed86b376f0b7492f2f4370a4e6a903a15d37f Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 19 Jan 2018 15:09:38 +0100 Subject: [PATCH 3/4] Setup a dummy registry to allow some more operations, e.g. accessing metadata --- scripts/db_shell.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/db_shell.py b/scripts/db_shell.py index 6850dede093..7fac545d943 100644 --- a/scripts/db_shell.py +++ b/scripts/db_shell.py @@ -30,13 +30,18 @@ from sqlalchemy.sql import label # noqa sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'lib'))) +from galaxy.datatypes.registry import Registry from galaxy.model import * # noqa +from galaxy.model import set_datatypes_registry # More expclicit than `*` import from galaxy.model.mapping import init from galaxy.model.orm.scripts import get_config if sys.version_info > (3,): long = int +registry = Registry() +registry.load_datatypes() +set_datatypes_registry(registry) db_url = get_config(sys.argv)['db_url'] sa_session = init('/tmp/', db_url).context From 89d45416fbb75d10ad43940308bd2e0dc4d2ede2 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 19 Jan 2018 15:27:55 +0100 Subject: [PATCH 4/4] Import Registry directly --- scripts/cleanup_datasets/cleanup_datasets.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/cleanup_datasets/cleanup_datasets.py b/scripts/cleanup_datasets/cleanup_datasets.py index c299a639da1..ee79b842396 100755 --- a/scripts/cleanup_datasets/cleanup_datasets.py +++ b/scripts/cleanup_datasets/cleanup_datasets.py @@ -19,7 +19,7 @@ sys.path.insert(1, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pa import galaxy.config import galaxy.model.mapping -from galaxy.datatypes import registry +from galaxy.datatypes.registry import Registry from galaxy.exceptions import ObjectNotFound from galaxy.objectstore import build_object_store_from_config from galaxy.util import unicodify @@ -527,9 +527,9 @@ class CleanupDatasetsApplication(object): self.object_store = build_object_store_from_config(config) # Setup the database engine and ORM self.model = galaxy.model.mapping.init(config.file_path, config.database_connection, engine_options={}, create_tables=False, object_store=self.object_store) - r = registry.Registry() - r.load_datatypes() - galaxy.model.set_datatypes_registry(r) + registry = Registry() + registry.load_datatypes() + galaxy.model.set_datatypes_registry(registry) @property def sa_session(self):