From 8eec0a607b121a8d4cac30a34d533d77755a74b9 Mon Sep 17 00:00:00 2001 From: Valentin Dumitru Date: Fri, 19 Jan 2024 18:56:27 +0200 Subject: [PATCH] Use more specific interface INamedBlobFileField for blob files and leave INamedFileField to be base64 encoded even with blob_paths selected --- CHANGES.rst | 5 +++++ src/collective/exportimport/configure.zcml | 1 + src/collective/exportimport/serializer.py | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index b74be6cb..8cf4e7b4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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] + - Fix ``KeyError: time`` when importing content with a workflow that does not have the ``time`` variable. [maurits] diff --git a/src/collective/exportimport/configure.zcml b/src/collective/exportimport/configure.zcml index 6e7cf577..9aef47fb 100644 --- a/src/collective/exportimport/configure.zcml +++ b/src/collective/exportimport/configure.zcml @@ -130,6 +130,7 @@ + diff --git a/src/collective/exportimport/serializer.py b/src/collective/exportimport/serializer.py index 2eed52f2..1f303ba2 100644 --- a/src/collective/exportimport/serializer.py +++ b/src/collective/exportimport/serializer.py @@ -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 @@ -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)