Commit e08ace32 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_discussion: discover metadata synchronously of discussion thread's attachment

When some types of files are attached to a forum thread, they may be
subjected to a portal type migration. This is the case of CSV files, for exemple. What
happens in that case, is that the document D1 is created with portal_type PT1, then
discoverMetadata is called, which triggers a portal type migration. Then D1 is deleted, and
recreated as D2 with portal type D2. The problem is that the migration happens after D1 was attached to
the Discussion Post (in a different transaction), so the relation between both is broken.
parent 90e96ee4
Pipeline #17334 failed with stage
in 0 seconds
...@@ -26,10 +26,12 @@ discussion_post = discussion_thread.newContent( ...@@ -26,10 +26,12 @@ discussion_post = discussion_thread.newContent(
# handle attachments # handle attachments
if getattr(file, 'filename', '') != '': if getattr(file, 'filename', '') != '':
document_kw = {'batch_mode': True, document = context.Base_contribute(
'redirect_to_document': False, batch_mode=True,
'file': file} redirect_to_document=False,
document = context.Base_contribute(**document_kw) synchronous_metadata_discovery=True,
file=file,
)
# set relation between post and document # set relation between post and document
discussion_post.setSuccessorValueList([document]) discussion_post.setSuccessorValueList([document])
......
...@@ -94,10 +94,12 @@ discussion_thread.publish() ...@@ -94,10 +94,12 @@ discussion_thread.publish()
# handle attachments # handle attachments
if getattr(file, 'filename', '') != '': if getattr(file, 'filename', '') != '':
document_kw = {'batch_mode': True, document = context.Base_contribute(
'redirect_to_document': False, batch_mode=True,
'file': file} redirect_to_document=False,
document = context.Base_contribute(**document_kw) synchronous_metadata_discovery=True,
file=file,
)
# set relation between post and document # set relation between post and document
discussion_post.setSuccessorValueList([document]) discussion_post.setSuccessorValueList([document])
......
...@@ -229,6 +229,47 @@ class TestERP5Discussion(ERP5TypeTestCase): ...@@ -229,6 +229,47 @@ class TestERP5Discussion(ERP5TypeTestCase):
s = "a test by ivan !@#$%^&*()[]\\é" s = "a test by ivan !@#$%^&*()[]\\é"
self.assertEqual('a-test-by-ivan', self.portal.Base_generateReferenceFromString(s)) self.assertEqual('a-test-by-ivan', self.portal.Base_generateReferenceFromString(s))
def test_AttachmentIngestion(self):
"""
Test the attachment of a CSV file, from both newDiscussionPost and newDiscussionThread
use cases.
CSV wasn't chosen randomly, as it may be subjected to a portal type migration through
discover metadata, which used to cause a bug.
"""
discussion_thread_id_set = set(self.portal.discussion_thread_module.objectIds())
web_site_value = self.portal.web_site_module.newContent(portal_type='Web Site')
web_section_value = web_site_value.newContent(portal_type='Web Section')
file_ = makeFileUpload('simple.csv')
web_section_value.WebSection_createNewDiscussionThread(
"Thread Title",
"Post Content",
file=file_
)
self.tic()
thread_value, = [
x for x in self.portal.discussion_thread_module.objectValues()
if x.getId() not in discussion_thread_id_set
]
post_value, = thread_value.objectValues(portal_type='Discussion Post')
tested_post_value_set = {post_value,}
attachment_list = post_value.DiscussionPost_getAttachmentList()
self.assertEqual(1, len(attachment_list))
thread_value.DiscussionThread_createNewDiscussionPost(
title="Post Title",
text_content="Post Content",
file=file_,
)
self.tic()
post_value, = [
x for x in thread_value.objectValues()
if x not in tested_post_value_set
]
attachment_list = post_value.DiscussionPost_getAttachmentList()
self.assertEqual(1, len(attachment_list))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Discussion)) suite.addTest(unittest.makeSuite(TestERP5Discussion))
......
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>testERP5Discussion</string> </value> <value> <string>testERP5Discussion</string> </value>
...@@ -53,13 +59,28 @@ ...@@ -53,13 +59,28 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -72,7 +93,7 @@ ...@@ -72,7 +93,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -81,7 +102,7 @@ ...@@ -81,7 +102,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
......
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