Commit 5a71ba9b authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_interface_post: improve allow_export's after-actions to be race-condition proof

parent 0523b99b
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery
# Because this script can be called at the ~ same time on different
# posts, it can raise race conditions where several posts disallow
# export of each other, resulting in nothing is exported. Checking
# the current state of the post here prevents a post which has
# already been disallowed to disallow the post which disalowed it.
# 2 Posts can still be exported at same time if one isn't indexed
# correctly yet.
if context.getSimulationState() != 'exportable':
return
# 1/ Disallow export of posts for the same origin message
portal = context.getPortalObject()
module = context.getParentValue()
......@@ -13,3 +25,6 @@ exportable_post_list = portal.portal_catalog(
for exportable_post in exportable_post_list:
exportable_post.disallowExport()
# 2/ Export post
context.InterfacePost_exportAfterAllowExport()
......@@ -54,7 +54,7 @@
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InterfacePost_disallowExportOfSameInterfacePostList</string> </value>
<value> <string>InterfacePost_disallowExportOfSameInterfacePostListAndExport</string> </value>
</item>
</dictionary>
</pickle>
......
post = state_change['object']
post.activate(tag='interface_post_disallow_export') \
.InterfacePost_disallowExportOfSameInterfacePostList()
post.activate(after_tag='interface_post_disallow_export') \
.InterfacePost_exportAfterAllowExport()
# Priority 2 is just enough to be executed after the immediateReindexObject
post.activate(serialization_tag='export_interface_post',
priority=2) \
.InterfacePost_disallowExportOfSameInterfacePostListAndExport()
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