From 968eaaf3a12d414093ea3de5ee46590cf0aa7cbe Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Fri, 5 Jul 2024 10:15:53 +0200 Subject: [PATCH 1/3] Fix several `UnboundLocalError` exceptions when doing automated import with `return_json=True` --- src/collective/exportimport/import_other.py | 49 +++++++-------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/src/collective/exportimport/import_other.py b/src/collective/exportimport/import_other.py index bfdea317..5522dbe9 100644 --- a/src/collective/exportimport/import_other.py +++ b/src/collective/exportimport/import_other.py @@ -88,11 +88,8 @@ def __call__(self, jsonfile=None, return_json=False): except Exception as e: logger.error(e) status = "error" - msg = e - api.portal.show_message( - _(u"Failure while uploading: {}").format(e), - request=self.request, - ) + msg = _(u"Failure while uploading: {}").format(e) + api.portal.show_message(msg, request=self.request) else: msg = self.do_import(data) api.portal.show_message(msg, self.request) @@ -194,10 +191,8 @@ def __call__(self, jsonfile=None, return_json=False): except Exception as e: status = "error" logger.error(e) - api.portal.show_message( - _(u"Failure while uploading: {}").format(e), - request=self.request, - ) + msg = _(u"Failure while uploading: {}").format(e) + api.portal.show_message(msg, request=self.request) else: groups = self.import_groups(data["groups"]) members = self.import_members(data["members"]) @@ -385,10 +380,8 @@ def __call__(self, jsonfile=None, return_json=False): except Exception as e: status = "error" logger.error(e) - api.portal.show_message( - _(u"Failure while uploading: {}").format(e), - request=self.request, - ) + msg = _(u"Failure while uploading: {}").format(e) + api.portal.show_message(msg, request=self.request) else: localroles = self.import_localroles(data) msg = _(u"Imported {} localroles").format(localroles) @@ -461,10 +454,8 @@ def __call__(self, jsonfile=None, return_json=False): except Exception as e: status = "error" logger.error(e) - api.portal.show_message( - _(u"Failure while uploading: {}").format(e), - request=self.request, - ) + msg = _(u"Failure while uploading: {}").format(e) + api.portal.show_message(msg, request=self.request) else: start = datetime.now() orders = self.import_ordering(data) @@ -519,10 +510,8 @@ def __call__(self, jsonfile=None, return_json=False): except Exception as e: status = "error" logger.error(e) - api.portal.show_message( - u"Failure while uploading: {}".format(e), - request=self.request, - ) + msg = u"Failure while uploading: {}".format(e) + api.portal.show_message(msg, request=self.request) else: defaultpages = self.import_default_pages(data) msg = _(u"Changed {} default pages").format(defaultpages) @@ -592,10 +581,8 @@ def __call__(self, jsonfile=None, return_json=False): except Exception as e: status = "error" logger.error(e) - api.portal.show_message( - _(u"Failure while uploading: {}").format(e), - request=self.request, - ) + msg = _(u"Failure while uploading: {}").format(e) + api.portal.show_message(msg, request=self.request) else: results = self.import_data(data) msg = _(u"Imported {} comments").format(results) @@ -688,10 +675,8 @@ def __call__(self, jsonfile=None, return_json=False): except Exception as e: status = "error" logger.error(e) - api.portal.show_message( - _(u"Failure while uploading: {}").format(e), - request=self.request, - ) + msg = _(u"Failure while uploading: {}").format(e) + api.portal.show_message(msg, request=self.request) else: portlets = self.import_portlets(data) msg = _(u"Created {} portlets").format(portlets) @@ -875,10 +860,8 @@ def __call__(self, jsonfile=None, return_json=False): except Exception as e: status = "error" logger.error(e) - api.portal.show_message( - _(u"Failure while uploading: {}").format(e), - request=self.request, - ) + msg = _(u"Failure while uploading: {}").format(e) + api.portal.show_message(msg, request=self.request) else: import_plone_redirects(data) msg = _(u"Redirects imported") From c59bed83c4823cd39d4a02870fef85f6b85d125b Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Fri, 5 Jul 2024 10:16:37 +0200 Subject: [PATCH 2/3] changenote --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index d2481e20..1772bedc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,10 @@ Changelog - Add and run a black version, that is compatible with Python 2. [pgrunewald] +- Fix several ``UnboundLocalError`` exceptions when doing automated import + with ``return_json=True`` + [petschki] + 1.12 (2024-03-08) ----------------- From d9df27b29eeda662c2491a9042302c0f029a2149 Mon Sep 17 00:00:00 2001 From: Peter Mathis Date: Fri, 5 Jul 2024 10:32:53 +0200 Subject: [PATCH 3/3] pin ijson for python 2 --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7c781dcf..24e9d485 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,6 @@ install_requires = [ "hurry.filesize", - "ijson", "setuptools", "six", ] @@ -31,6 +30,7 @@ install_requires.append("jsonschema < 4") install_requires.append("pathlib2") install_requires.append("plone.api >= 1.8.4, < 2") + install_requires.append("ijson < 3.3.0") # There is a py2-imcompatibility in plone.rest 3.0.1 install_requires.append("plone.rest < 3.0.1") install_requires.append("plone.restapi < 8") @@ -39,6 +39,7 @@ install_requires.append("pyrsistent < 0.16.0") else: install_requires.append("beautifulsoup4") + install_requires.append("ijson") install_requires.append("plone.api >= 1.8.4") install_requires.append("plone.restapi")