Commit a5a2f1cd by Tomáš Peterka Committed by Tomáš Peterka

[erp5] FormBoxEditor keeps correct context as its attribute

parent b596deaa
......@@ -42,6 +42,7 @@ from Products.PythonScripts.standard import url_quote_plus
from Products.Formulator.Errors import FormValidationError, ValidationError
import string
import copy
class FormBoxWidget(Widget.Widget):
"""
......@@ -123,9 +124,15 @@ class FormBoxEditor:
"""
A class holding all values required to update the object
"""
def __init__(self, field_id, result):
def __init__(self, field_id, result, context=None):
"""Initialize with all necessary information for editing.
Keep a reference to the correct context and don't expect the caller to provide it
during the edit phase because they don't have access to the widget anymore.
"""
self.field_id = field_id
self.result = result
self.attr_dict, self.editor_list = result
self.context = context
def view(self):
return self.__dict__
......@@ -134,8 +141,12 @@ class FormBoxEditor:
pass
def edit(self, context):
context.edit(**self.result[0])
for encapsulated_editor in self.result[1]:
"""Edit inside correct context."""
if self.context is not None:
context = self.context
context.edit(**self.attr_dict)
for encapsulated_editor in self.editor_list:
encapsulated_editor.edit(context)
def as_dict(self):
......@@ -144,8 +155,8 @@ class FormBoxEditor:
XXX This API is probably not stable and may change, as some editors are used to
edit multiple objects.
"""
result_dict = self.result[0]
for encapsulated_editor in self.result[1]:
result_dict = copy.copy(self.attr_dict)
for encapsulated_editor in self.editor_list:
if hasattr(encapsulated_editor, 'as_dict'):
result_dict.update(
encapsulated_editor.as_dict())
......@@ -181,7 +192,7 @@ class FormBoxValidator(Validator.Validator):
# XXX Hardcode script name
result, result_type = here.Base_edit(formbox_target_id, silent_mode=1, key_prefix=key)
if result_type == 'edit':
return FormBoxEditor(field.id, result)
return FormBoxEditor(field.id, result, context=here)
elif result_type == 'form':
formbox_field_errors = REQUEST.get('field_errors', [])
current_field_errors.extend(formbox_field_errors)
......
  • This breaks 2 tests:

    ======================================================================
    FAIL: test_normal_form (testDeferredStyle.TestODSDeferredStyle)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/srv/slapgrid/slappart5/srv/testnode/asg/soft/6e6f41acb31007fd55a70521ee8290a0/parts/erp5/Products/ERP5OOo/tests/testDeferredStyle.py", line 130, in test_normal_form
        self.assertNotEquals((), last_message)
    AssertionError: () == ()
    
    ======================================================================
    FAIL: test_normal_form (testDeferredStyle.TestODTDeferredStyle)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/srv/slapgrid/slappart5/srv/testnode/asg/soft/6e6f41acb31007fd55a70521ee8290a0/parts/erp5/Products/ERP5OOo/tests/testDeferredStyle.py", line 149, in test_normal_form
        self.fail('Attachment not found in email\n%s' % message_text)
    AssertionError: Attachment not found in email
  • Are you sure it is my commit which broke those tests? I don't see any link ...

    Edited by Tomáš Peterka
  • Yes, this commit broke testDeferredStyle. To understand more, here is the zope log with the test :

    2017-08-31 14:57:24.870 INFO Tracking queuing message: activity=SQLQueue, object_path=/erp5/person_module/pers, method_id=Base_renderSimpleView, args=(), kw={'request_form': {'default_fax': <Products.ERP5Form.FormBox.FormBoxEditor instance at 0x7fe89c0ebc68>, 'dialog_id': 'Person_view', 'junk': 'XXX...XXX', 'dialog_method': 'Person_view', 'deferred_portal_skin': 'ODT', 'default_telephone': <Products.ERP5Form.FormBox.FormBoxEditor instance at 0x7fe89b2bd098>, 'mobile_telephone': <Products.ERP5Form.FormBox.FormBoxEditor instance at 0x7fe8928835f0>, 'deferred_style': 1}, 'params': {}, 'localizer_language': 'en', 'skin_name': 'ODT', 'user_name': 'P0', 'deferred_style_dialog_method': 'Person_view'}, activity_kw={'priority': 3, 'tag': 'active-report-wrapped-843'}, user_name=P0
    2017-08-31 14:57:24.870 INFO Tracking queuing message: activity=SQLQueue, object_path=/erp5/person_module/pers, method_id=getTitle, args=(), kw={}, activity_kw={'after_tag': 'active-report-wrapped-843'}, user_name=P0
    2017-08-31 14:57:24.875 ERROR ActivityBuffer exception during _prepare
    Traceback (most recent call last):
      File "/srv/slapgrid/slappart0/srv/runner/software/d65309081a071d10fa34fce376e82fd7/parts/erp5/product/CMFActivity/ActivityBuffer.py", line 64, in _prepare
        activity.prepareQueueMessageList(activity_tool, message_list)
      File "/srv/slapgrid/slappart0/srv/runner/software/d65309081a071d10fa34fce376e82fd7/parts/erp5/product/CMFActivity/Activity/SQLBase.py", line 147, in prepareQueueMessageList
        message_list=map(Message.dump, message_list),
    TypeError: Can't pickle objects in acquisition wrappers.

    You can see that default_fax, default_telephone and mobile_telephone arguments are ERP5 objects (i.e. acquisition wrappers that cannot be pickled).

  • mentioned in merge request !363 (merged)

    Toggle commit list
  • Hi, thank you for the help. I came up with a fix - full test results coming up https://nexedijs.erp5.net/#/test_result_module/20170831-29851556

  • mentioned in commit 566c0c5f

    Toggle commit list
  • Thank you @jm and @kazuhiko for help with thracking it down. I merged the fix this morning after the tests passed

  • mentioned in commit Sokhoyan/erp5@7140dbc0

    Toggle commit list
  • mentioned in merge request !622 (merged)

    Toggle commit list
  • mentioned in commit ab388d7f

    Toggle commit list
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 sign in to comment