Issue #1457
closedunit.import_content() failure leaves file-less unit in DB
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):
"""
Updated by ipanova@redhat.com about 8 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to pcreech
Added by pcreech about 8 years ago
Added by pcreech about 8 years ago
Revision f1d1c092 | View on GitHub
Ensure file objects are cleaned up on error
Call save_and_import_content().
Utilize cleanup pattern instead where usage doesn't fit.
Added by pcreech about 8 years ago
Revision 5b41b3fb | View on GitHub
Ensure file objects are cleaned up on error
Call save_and_import_content().
Utilize cleanup pattern instead where usage doesn't fit.
Added by pcreech about 8 years ago
Revision 5b41b3fb | View on GitHub
Ensure file objects are cleaned up on error
Call save_and_import_content().
Utilize cleanup pattern instead where usage doesn't fit.
Added by pcreech about 8 years ago
Revision 5b41b3fb | View on GitHub
Ensure file objects are cleaned up on error
Call save_and_import_content().
Utilize cleanup pattern instead where usage doesn't fit.
Added by pcreech about 8 years ago
Revision 5b41b3fb | View on GitHub
Ensure file objects are cleaned up on error
Call save_and_import_content().
Utilize cleanup pattern instead where usage doesn't fit.
Added by pcreech about 8 years ago
Revision 24a2d27e | View on GitHub
Ensure file objects are cleaned up on error
Call save_and_import_content().
Utilize cleanup pattern instead where usage doesn't fit.
Added by pcreech about 8 years ago
Revision 17b437f0 | View on GitHub
Ensure file objects are cleaned up on error
Plugins save then call import_content on FileContentUnit objects. This ensures that if an error happens on import_content, we also clean up after ourselves.
Added by pcreech about 8 years ago
Revision 17b437f0 | View on GitHub
Ensure file objects are cleaned up on error
Plugins save then call import_content on FileContentUnit objects. This ensures that if an error happens on import_content, we also clean up after ourselves.
Updated by dkliban@redhat.com about 8 years ago
- Status changed from MODIFIED to 5
Updated by dkliban@redhat.com almost 8 years ago
- Status changed from 5 to CLOSED - CURRENTRELEASE
Ensure file objects are cleaned up on error
Call save_and_import_content().
re #1457 https://pulp.plan.io/issues/1457