Merge pull request #5346 from mvdbeek/fix_hda_parent_access

Fix dataset purging, dataset cleanup script and db_shell script
This commit is contained in:
John Chilton
2018-01-21 14:10:32 -05:00
committed by GitHub
3 changed files with 14 additions and 13 deletions
@@ -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
+7 -7
View File
@@ -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.registry 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)
registry = Registry()
registry.load_datatypes()
galaxy.model.set_datatypes_registry(registry)
@property
def sa_session(self):
+5
View File
@@ -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