Skip to content

Commit

Permalink
Try to restore broken blobs when exporting content.
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Nov 12, 2023
1 parent d3946d8 commit f1f626f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
1.11 (unreleased)
-----------------

- Try to restore broken blobs when exporting content.
[thet]

- When exporting into separate JSON files write also the error in a separate errors.json file.
This fixes an error at the end of the export and no errors being written.
[thet]
Expand Down
24 changes: 20 additions & 4 deletions src/collective/exportimport/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,26 @@ def __call__(self):
if namedfile is None:
return None

if "built-in function id" in namedfile.filename:
filename = self.context.id
else:
filename = namedfile.filename
try:
if "built-in function id" in namedfile.filename:
filename = self.context.id
else:
filename = namedfile.filename
except AttributeError:
# Try to recover broken namedfile
# Related to: WARNING OFS.Uninstalled Could not import class 'NamedBlobFile' from module 'zope.app.file.file'
from ZODB.broken import Broken
if isinstance(namedfile, Broken):
broken_namedfile = namedfile.__Broken_state__
file = broken_namedfile["_blob"].open()
result = {
"filename": broken_namedfile["filename"],
"content-type": broken_namedfile["contentType"],
"data": base64.b64encode(file.read()),
"encoding": "base64",
}
file.close()
return result

result = {
"filename": filename,
Expand Down

0 comments on commit f1f626f

Please sign in to comment.