unit.import_content() failure leaves file-less unit in DB
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): """