Commit ee5017ac authored by Titouan Soulard's avatar Titouan Soulard

erp5_api_style: abort transaction on error

When an error was encountered in `jIOWebSection`, it did not abort the
transaction, as it usually does in ERP5. This was made on purpose because
errors are logged in ZODB, hence aborting the transaction didn't make it
possible.

This behavior was annoying, so this commit purposedly abort transaction before
starting a new one to handle error. We are therefore able to log error in ZODB
while also keeping the usual ERP5 behavior of aborting on error.
parent 35a1119d
Pipeline #37524 passed with stage
...@@ -32,6 +32,8 @@ from Acquisition import aq_inner ...@@ -32,6 +32,8 @@ from Acquisition import aq_inner
from zExceptions import NotFound, Unauthorized from zExceptions import NotFound, Unauthorized
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
import transaction
from erp5.component.mixin.DocumentExtensibleTraversableMixin import DocumentExtensibleTraversableMixin from erp5.component.mixin.DocumentExtensibleTraversableMixin import DocumentExtensibleTraversableMixin
from erp5.component.document.WebSection import WebSection from erp5.component.document.WebSection import WebSection
...@@ -97,8 +99,17 @@ class jIOMethod(object): ...@@ -97,8 +99,17 @@ class jIOMethod(object):
# Avoid information leak when Unauthorized # Avoid information leak when Unauthorized
del error_context["error_message"] del error_context["error_message"]
# Skin used to allow replacement and because Manager proxy role is needed transaction.abort()
self.web_section.ERP5Site_logApiErrorAndReturn(**error_context) transaction.begin()
try:
# Skin used to allow replacement and because Manager proxy role is needed
self.web_section.ERP5Site_logApiErrorAndReturn(**error_context)
except:
transaction.abort()
return
transaction.commit()
class jIOWebSection(WebSection): class jIOWebSection(WebSection):
portal_type = "jIO Web Section" portal_type = "jIO Web Section"
...@@ -121,7 +132,7 @@ class jIOWebSection(WebSection): ...@@ -121,7 +132,7 @@ class jIOWebSection(WebSection):
section = section.aq_parent section = section.aq_parent
return default return default
security.declareProtected(Permissions.View, "_bobo_traverse__") security.declareProtected(Permissions.View, "__bobo_traverse__")
def __bobo_traverse__(self, request, name): def __bobo_traverse__(self, request, name):
if name in ALLOWED_MODES: if name in ALLOWED_MODES:
return jIOMethod(name, self) return jIOMethod(name, self)
......
...@@ -45,7 +45,9 @@ ...@@ -45,7 +45,9 @@
<item> <item>
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple/> <tuple>
<string>W:108, 6: No exception type(s) specified (bare-except)</string>
</tuple>
</value> </value>
</item> </item>
<item> <item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment