Can not edit existing Products.PloneFormGen folders: Unicode errors (Plone 5.1.5)

I've updated a site from 5.1.4 to 5.1.5 and I can now no longer edit a plone.formgen folder.

If I navigate to an existing formgen (1.8.5) folder I can not edit any more. Clicking on the edit button generates the error below:

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 32, in _call
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.CMFCore.FSPageTemplate, line 237, in _exec
  Module Products.CMFCore.FSPageTemplate, line 177, in pt_render
  Module Products.PageTemplates.PageTemplate, line 87, in pt_render
  Module zope.pagetemplate.pagetemplate, line 137, in pt_render
  Module five.pt.engine, line 98, in __call__
  Module z3c.pt.pagetemplate, line 163, in render
  Module chameleon.zpt.template, line 261, in render
  Module chameleon.template, line 191, in render
  Module chameleon.template, line 171, in render
  Module 0ba8d5ec1486047f76c5e57e919a6d18.py, line 1142, in render
  Module 0ba8d5ec1486047f76c5e57e919a6d18.py, line 963, in render_master
  Module d31f1ddede68c5e92cc565bc09266ed0.py, line 1223, in render_master
  Module d31f1ddede68c5e92cc565bc09266ed0.py, line 458, in render_content
  Module 0ba8d5ec1486047f76c5e57e919a6d18.py, line 951, in __fill_main
  Module 0ba8d5ec1486047f76c5e57e919a6d18.py, line 122, in render_main
  Module f8ae4443f7d0cd9eee99e5d6d118771c.py, line 455, in render_body
  Module a76c14eb0ed31289b4624e8e77a551ff.py, line 138, in render_edit
  Module 80ffcbb5280a0f1f51340d52befa2890.py, line 655, in render_edit
  Module a76c14eb0ed31289b4624e8e77a551ff.py, line 100, in __fill_widget_body
  Module Products.Archetypes.Widget, line 1475, in edit
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 508: ordinal not in range(128)

 - Expression: "python:widget.edit(context, field, request)"
 - Filename:   ... Products/Archetypes/browser/templates/patterns_widget.pt
 - Location:   (line 19: col 36)
 - Source:     ... tructure python:widget.edit(context, field, request)"></div>
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  repeat: {...} (0)
               template: <ImplicitAcquisitionWrapper base_edit at 0x7fcfe34005a0>
               modules: <instance - at 0x7fcfea8a1320>
               here: <ImplicitAcquisitionWrapper pre-application-form at 0x7fcfe3452370>
               user: <ImplicitAcquisitionWrapper - at 0x7fcfe3400230>
               nothing: <NoneType - at 0x789160>
               container: <ImplicitAcquisitionWrapper ipes-cdt at 0x7fcfe3186280>
               default: <object - at 0x7fcffaab0ab0>
               request: <instance - at 0x7fcfd9dd7b90>
               wrapped_repeat: <SafeMapping - at 0x7fcfda4987e0>
               traverse_subpath: <list - at 0x7fcfd9de7e18>
               loop: {...} (3)
               context: <ImplicitAcquisitionWrapper pre-application-form at 0x7fcfe3452370>
               translate: <function translate at 0x7fcfd9e5a320>
               root: <ImplicitAcquisitionWrapper Zope at 0x7fcfe3310280>
               options: {...} (2)
               target_language: <NoneType - at 0x789160>

I can create new forms and edit those, but I don;t really want to have to recreate all forms on the site.

Any suggestions would be most appreciated!

Something forces a unicode string into str -- what is should not do (it is too early). Look near line 1475 of Products.Archetypes.Widget to check whether the conversion can be avoider.

I created a new form and added Arabic text to Form Prologue. After saving, the Arabic text was showing correctly. However, it gave me an error when I tried to re-edit the form as below.

Traceback (innermost last):
Module ZPublisher.Publish, line 138, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 48, in call_object
Module Products.CMFFormController.FSControllerPageTemplate, line 91, in call
Module Products.CMFFormController.BaseControllerPageTemplate, line 32, in _call
Module Shared.DC.Scripts.Bindings, line 322, in call
Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
Module Products.CMFCore.FSPageTemplate, line 237, in _exec
Module Products.CMFCore.FSPageTemplate, line 177, in pt_render
Module Products.PageTemplates.PageTemplate, line 87, in pt_render
Module zope.pagetemplate.pagetemplate, line 137, in pt_render
Module five.pt.engine, line 98, in call
Module z3c.pt.pagetemplate, line 163, in render
Module chameleon.zpt.template, line 261, in render
Module chameleon.template, line 191, in render
Module chameleon.template, line 171, in render
Module a912309d53ade9ef50884daadc68edf1.py, line 1142, in render
Module a912309d53ade9ef50884daadc68edf1.py, line 963, in render_master
Module 730bfe5ca2807be0a2a5da82bbe1a4d2.py, line 1223, in render_master
Module 730bfe5ca2807be0a2a5da82bbe1a4d2.py, line 458, in render_content
Module a912309d53ade9ef50884daadc68edf1.py, line 951, in __fill_main
Module a912309d53ade9ef50884daadc68edf1.py, line 122, in render_main
Module ecbebcbcdcbd625f5189e314cd1ddf82.py, line 455, in render_body
Module b498c0a148db25e58637684ca4cf4a06.py, line 138, in render_edit
Module 3f45abbe55150f4e88c346d984d516c7.py, line 655, in render_edit
Module b498c0a148db25e58637684ca4cf4a06.py, line 100, in __fill_widget_body
Module Products.Archetypes.Widget, line 1475, in edit
UnicodeEncodeError: 'ascii' codec can't encode characters in position 48-51: ordinal not in range(128)

  • Expression: "python:widget.edit(context, field, request)"
  • Filename: ... products\Archetypes\browser\templates\patterns_widget.pt
  • Location: (line 19: col 36)
  • Source: ... tructure python:widget.edit(context, field, request)">
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  • Arguments: repeat: {...} (0)
    template: <ImplicitAcquisitionWrapper base_edit at 0xf430f98L>
    modules: <instance - at 0x4a04848L>
    here: <ImplicitAcquisitionWrapper calculate-painting-quantity at 0xf430368L>
    user: <ImplicitAcquisitionWrapper - at 0xf430188L>
    nothing: <NoneType - at 0x6175fa98L>
    container: <ImplicitAcquisitionWrapper calculate-painting-quantity at 0xf430368L>
    default: <object - at 0x44ef0a0L>
    request: <instance - at 0xe022b08L>
    wrapped_repeat: <SafeMapping - at 0xf4306d8L>
    traverse_subpath: <list - at 0xdd0d9c8L>
    loop: {...} (3)
    context: <ImplicitAcquisitionWrapper calculate-painting-quantity at 0xf430368L>
    translate: <function translate at 0xf016128L>
    root: <ImplicitAcquisitionWrapper Zope at 0xf2baf48L>
    options: {...} (2)
    target_language: <NoneType - at 0x6175fa98L>

Look at the code around line 1475 of Products.Archetypes.Widget. There, unicode arrives and is for some reason encoded using a wrong encoding. Try to find out what tries the encoding and why it may be using a wrong encoding.

Thanks for your feedback dieter. I did fix the problem at that location in the widget file by replacing the format statement by a normal string concatenation