From 44286b4eef5706c48b0884729cf5dc3829fd3103 Mon Sep 17 00:00:00 2001 From: Alex Ioannidis Date: Mon, 9 Oct 2023 13:45:40 +0200 Subject: [PATCH] files: handle disabled state on deleting draft --- .../services/records/components/base.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/invenio_drafts_resources/services/records/components/base.py b/invenio_drafts_resources/services/records/components/base.py index fe633ed..efddd22 100644 --- a/invenio_drafts_resources/services/records/components/base.py +++ b/invenio_drafts_resources/services/records/components/base.py @@ -186,11 +186,12 @@ def new_version(self, identity, draft=None, record=None): def _purge_bucket_and_ovs(self, files): """Purge associated bucket and object versions.""" - if files.bucket.locked: - files.unlock() - if files.enabled: - files.delete_all(softdelete_obj=False, remove_rf=True) - files.remove_bucket(force=True) + if files.bucket: + if files.bucket.locked: + files.unlock() + if files.enabled: + files.delete_all(softdelete_obj=False, remove_rf=True) + files.remove_bucket(force=True) def _publish_new(self, identity, draft, record): """Action when publishing a new draft.""" @@ -275,7 +276,7 @@ def delete_draft(self, identity, draft=None, record=None, force=False): """ draft_files = self.get_record_files(draft) - # Teardown the bucket and files. + # Teardown the bucket and files if any. self._purge_bucket_and_ovs(draft_files) def import_files(self, identity, draft=None, record=None):