Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AtributeError 'NamedFile' object has no attribute '_blob' when exporting objects with plone.namedfile.file.NamedFile properties #236

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Changelog
1.11 (unreleased)
-----------------

- Fix ``AtributeError: 'NamedFile' object has no attribute '_blob'`` when using setting
"Include blobs as blob paths" and exporting objects with
plone.namedfile.file.NamedFile properties (so not blobs).
[valipod]

- Add more Python 2 compatible version specifications and update the README.
[thet]

Expand Down
1 change: 1 addition & 0 deletions src/collective/exportimport/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<!-- Serializers -->
<adapter factory=".serializer.FileFieldSerializerWithBlobs" />
<adapter factory=".serializer.FileFieldSerializerWithBlobPaths" />
<adapter factory=".serializer.FileFieldSerializerZODBData" />
<adapter factory=".serializer.ImageFieldSerializerWithBlobs" />
<adapter factory=".serializer.ImageFieldSerializerWithBlobPaths" />
<adapter factory=".serializer.RichttextFieldSerializerWithRawText" />
Expand Down
11 changes: 10 additions & 1 deletion src/collective/exportimport/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from hurry.filesize import size
from plone.app.textfield.interfaces import IRichText
from plone.dexterity.interfaces import IDexterityContent
from plone.namedfile.interfaces import INamedFileField
from plone.namedfile.interfaces import INamedFileField, INamedBlobFileField
from plone.namedfile.interfaces import INamedImageField
from plone.restapi.interfaces import IFieldSerializer
from plone.restapi.interfaces import IJsonCompatible
Expand Down Expand Up @@ -549,6 +549,15 @@ def get_dx_blob_path(obj):

@adapter(INamedFileField, IDexterityContent, IPathBlobsMarker)
@implementer(IFieldSerializer)
class FileFieldSerializerZODBData(FileFieldSerializerWithBlobs):
""" Although the marker is IPathBlobsMarker, this being a plain NamedFile
object, its data is in the ZODB, thus this still needs to be
base64 encoded into the JSON file
So we just subclass from the above FileFieldSerializerWithBlobs """


@adapter(INamedBlobFileField, IDexterityContent, IPathBlobsMarker)
@implementer(IFieldSerializer)
class FileFieldSerializerWithBlobPaths(DefaultFieldSerializer):
def __call__(self):
namedfile = self.field.get(self.context)
Expand Down