From b329b2b7a6cbcbf8a0e7c3d149829ea1dd9f9590 Mon Sep 17 00:00:00 2001 From: Godefroid Chapelle Date: Thu, 27 Jul 2023 10:36:57 +0200 Subject: [PATCH 1/3] Better support for portal import. Avoid parsing JSON twice and dumping once for each content object. The only deserializer that does not support data as keyword argument is the portal deserializer. For all other content items, dumping to JSON to setup the request before loading from JSON in the `json_body` function is really overkill as the item has already been parsed when loaded from file. --- src/collective/exportimport/import_content.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/collective/exportimport/import_content.py b/src/collective/exportimport/import_content.py index 0d37127c..dd3e332f 100644 --- a/src/collective/exportimport/import_content.py +++ b/src/collective/exportimport/import_content.py @@ -428,9 +428,15 @@ def handle_new_object(self, item, index, new): # import using plone.restapi deserializers deserializer = getMultiAdapter((new, self.request), IDeserializeFromJson) - self.request["BODY"] = json.dumps(item) try: - new = deserializer(validate_all=False) + try: + new = deserializer(validate_all=False, data=item) + except TypeError as error: + if 'unexpected keyword argument' in str(error): + self.request["BODY"] = json.dumps(item) + new = deserializer(validate_all=False) + else: + raise error except Exception: logger.warning("Cannot deserialize %s %s", item["@type"], item["@id"], exc_info=True) raise From b25af0ce3ae1484c0842b0a95b3d6db0bd75d3b2 Mon Sep 17 00:00:00 2001 From: Philip Bauer Date: Fri, 29 Sep 2023 17:26:18 +0200 Subject: [PATCH 2/3] add changenote --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 31ee8944..17144477 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,8 @@ Changelog - Don't re-use `mapping` variable when migrating portlet data. [witsch] +- Better support for portal import which avoids parsing JSON twice. + [gotcha] 1.9 (2023-05-18) ---------------- From 0821e7cee6de3377da08d8a7ad144f0eb1b94ad6 Mon Sep 17 00:00:00 2001 From: Philip Bauer Date: Fri, 29 Sep 2023 17:26:50 +0200 Subject: [PATCH 3/3] fix issue with plone.rest 3.0.1 in py2 for now --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 6cca2ac3..6980e329 100644 --- a/setup.py +++ b/setup.py @@ -26,6 +26,8 @@ if sys.version_info[0] < 3: install_requires.append("beautifulsoup4 < 4.10") install_requires.append("plone.restapi < 8.0.0") + # There is a py2-imcompatibility in plone.rest 3.0.1 + install_requires.append("plone.rest < 3.0.1") # plone.restapi depends on plone.schema, which depends on jsonschema, # which has a Py3-only release since September 2021. install_requires.append("jsonschema < 4")