From 63709fd4a7b4f38e6072061b1d74e2022403f797 Mon Sep 17 00:00:00 2001 From: Bryton Lacquement Date: Thu, 31 Oct 2019 17:07:21 +0100 Subject: [PATCH] ... This is a follow up commit to cd18daf41128ac5ba69dafd62fbc72b43103f680, to fix the behavior in WSGI. Zope WSGI no longer works like Medusa in the case of "response.write". Before this change, the response contained the contents of "response.stdout" (which we want), plus the contents of the body (the traceback created by the raised Exception, which we do not want). Note that the "content-length" header was not correctly set either, and parts of the response were cut off. Reminder: raising an exception is done in order to doom the transaction. We are working on reimplementing WSGI/Medusa compatible streaming in a better way in the near future; this commit is a temporary fix. --- .../BusinessTemplate_getDiffWithZODBAsHTML.py | 4 ++-- .../BusinessTemplate_getDiffWithZODBAsText.py | 4 ++-- .../erp5_core/CategoryTool_importCategoryFile.py | 10 ++++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/BusinessTemplate_getDiffWithZODBAsHTML.py b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/BusinessTemplate_getDiffWithZODBAsHTML.py index 92fdb21cacf..0f88b8239f9 100644 --- a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/BusinessTemplate_getDiffWithZODBAsHTML.py +++ b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/BusinessTemplate_getDiffWithZODBAsHTML.py @@ -2,7 +2,7 @@ def respond(v): if REQUEST is None: return v REQUEST.RESPONSE.setHeader("Content-Type", "text/html") - REQUEST.RESPONSE.write(v) - raise ValueError("Abort Transaction") + REQUEST.RESPONSE.setBody(v, lock=True) + raise Exception return respond(context.Base_formatDiffObjectListToHTML(context.BusinessTemplate_getDiffObjectListFromZODB(detailed=detailed))) diff --git a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/BusinessTemplate_getDiffWithZODBAsText.py b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/BusinessTemplate_getDiffWithZODBAsText.py index aecd760aa33..f4a7f1b49a1 100644 --- a/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/BusinessTemplate_getDiffWithZODBAsText.py +++ b/bt5/erp5_forge/SkinTemplateItem/portal_skins/erp5_toolbox/BusinessTemplate_getDiffWithZODBAsText.py @@ -1,7 +1,7 @@ def respond(v): if REQUEST is None: return v - REQUEST.RESPONSE.write(v) - raise ValueError("Abort Transaction") + REQUEST.RESPONSE.setBody(v, lock=True) + raise Exception return respond(context.Base_formatDiffObjectListToText(context.BusinessTemplate_getDiffObjectListFromZODB(detailed=detailed))) diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.py b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.py index 6516eb5a8bc..41d4aaa549b 100644 --- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.py +++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.py @@ -57,8 +57,9 @@ category_list_spreadsheet_dict = context.Base_getCategoriesSpreadSheetMapping( if detailed_report_result: REQUEST.other['portal_status_message'] = translateString('Spreasheet contains errors') REQUEST.other['category_import_report'] = detailed_report_result - REQUEST.RESPONSE.write(portal_categories.CategoryTool_viewImportReport().encode('utf-8')) - raise Exception('Spreadsheet contains errors') + REQUEST.RESPONSE.setBody(portal_categories.CategoryTool_viewImportReport().encode('utf-8'), lock=True) + # Spreadsheet contains errors + raise Exception for base_category, category_list in category_list_spreadsheet_dict.iteritems(): total_category_counter += len(category_list) @@ -211,8 +212,9 @@ if detailed_report: REQUEST.other['category_import_report'] = detailed_report_result result = portal_categories.CategoryTool_viewImportReport().encode('utf-8') if simulation_mode: - REQUEST.RESPONSE.write(result) - raise Exception('Dry run') + REQUEST.RESPONSE.setBody(result, lock=True) + # Dry run + raise Exception return result portal_categories.Base_redirect( keep_items={ -- 2.30.9