From 238d908ccecd6411a3a72f7396933b3771f7e5aa Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Wed, 19 Aug 2015 12:39:41 +0100 Subject: [PATCH 1/2] Fix purging datasets whose total_size is None. Fix the error: Removing disk, file /opt/galaxy/database/files/000/dataset_192.dat Error attempting to purge data file: /opt/galaxy/database/files/000/dataset_192.dat error: unsupported operand type(s) for -=: 'Decimal' and 'NoneType' when running: python scripts/cleanup_datasets/cleanup_datasets.py config/galaxy.ini -d 10 -3 -r --- lib/galaxy/model/__init__.py | 12 +++++------- scripts/cleanup_datasets/cleanup_datasets.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 4bdc69f49d3..23d92ead110 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -1434,13 +1434,11 @@ class Dataset( object ): def get_total_size( self ): if self.total_size is not None: return self.total_size - if self.file_size: - # for backwards compatibility, set if unset - self.set_total_size() - db_session = object_session( self ) - db_session.flush() - return self.total_size - return 0 + # for backwards compatibility, set if unset + self.set_total_size() + db_session = object_session( self ) + db_session.flush() + return self.total_size def set_total_size( self ): if self.file_size is None: self.set_size() diff --git a/scripts/cleanup_datasets/cleanup_datasets.py b/scripts/cleanup_datasets/cleanup_datasets.py index 11cd27b95f4..db6bcd6954f 100644 --- a/scripts/cleanup_datasets/cleanup_datasets.py +++ b/scripts/cleanup_datasets/cleanup_datasets.py @@ -465,7 +465,7 @@ def _purge_dataset( app, dataset, remove_from_disk, info_only = False ): if hda.history.user is not None and hda.history.user not in usage_users: usage_users.append( hda.history.user ) for user in usage_users: - user.total_disk_usage -= dataset.total_size + user.total_disk_usage -= dataset.get_total_size() app.sa_session.add( user ) print "Purging dataset id", dataset.id dataset.purged = True From a9827fae31d8826bf2426c5285fe789dfe61295d Mon Sep 17 00:00:00 2001 From: John Chilton Date: Thu, 20 Aug 2015 06:45:11 +0100 Subject: [PATCH 2/2] Fix failing tests for 238d908ccecd6411a3a72f7396933b3771f7e5aa. --- test/unit/test_galaxy_mapping.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/unit/test_galaxy_mapping.py b/test/unit/test_galaxy_mapping.py index 468b0a3d91b..403c0627f2d 100644 --- a/test/unit/test_galaxy_mapping.py +++ b/test/unit/test_galaxy_mapping.py @@ -413,7 +413,7 @@ class MappingTests( unittest.TestCase ): @classmethod def setUpClass(cls): # Start the database and connect the mapping - cls.model = mapping.init( "/tmp", "sqlite:///:memory:", create_tables=True ) + cls.model = mapping.init( "/tmp", "sqlite:///:memory:", create_tables=True, object_store=MockObjectStore() ) assert cls.model.engine is not None @classmethod @@ -442,6 +442,21 @@ class MappingTests( unittest.TestCase ): cls.model.session.expunge_all() +class MockObjectStore(object): + + def __init__(self): + pass + + def size(self, dataset): + return 42 + + def exists(self, *args, **kwds): + return True + + def get_filename(self, *args, **kwds): + return "dataest_14.dat" + + def get_suite(): suite = unittest.TestSuite() suite.addTest( MappingTests( "test_basic" ) )