Project

Profile

Help

Issue #1457

closed

unit.import_content() failure leaves file-less unit in DB

Added by mhrivnak over 8 years ago. Updated almost 5 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Master
Platform Release:
2.8.0
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Pulp 2
Sprint:
Quarter:

Description

Plugins used to move a unit's files into place and then save the unit in the DB. With 2.8, this had to be reversed.

So if the import_content() call fails, the unit will be left in the database without having files. This is a difficult state to recover from.

A potential solution is to help plugins attempt to undo the save if the import_content call fails. Something like this on FileUnit might work:

diff --git a/server/pulp/server/db/model/__init__.py b/server/pulp/server/db/model/__init__.py
index a6ba85b..6d2454f 100644
--- a/server/pulp/server/db/model/__init__.py
+++ b/server/pulp/server/db/model/__init__.py
@@ -761,6 +761,14 @@ class FileContentUnit(ContentUnit):
         with FileStorage() as storage:
             storage.put(self, path, location)

+    def save_and_import_content(self, path, location=None):
+        self.save()
+        try:
+            self.import_content(path, location)
+        except Exception:
+            self.delete()
+            raise
+

 class SharedContentUnit(ContentUnit):
     """

Also available in: Atom PDF