plone / plone.app.widgets

Integrating plone.widgets into plone
Other
7 stars 38 forks source link

ValueError in base.SelectWidget._set_items() when title contains unicode #153

Open fulv opened 7 years ago

fulv commented 7 years ago

collective.contentrules.mailtogroup has the following field definition:

from plone.app.z3cform.widget import SelectWidget
from plone.autoform import directives
from zope import schema
from zope.interface import Interface

class IMailGroupAction(Interface):
    ...

    directives.widget('groups', SelectWidget)
    groups = schema.List(
        title=_(u'Group(s) to mail'),
        description=_('The group where you want to send this message. All \
            members of the group will receive an email.'),
        value_type=schema.Choice(vocabulary=u'plone.principalsource.Groups'),
        required=False
    )

In other words, the List allows you to select from a dict of existing user groups on the site. When one of the group titles (not the id) contains a unicode character (in this case "Öhlen"), it results in the following traceback:

2017-02-07T19:57:57 ERROR Zope.SiteErrorLog 1486526277.870.52632620218 http://localhost:8080/Plone/++rule++rule-1/+action/plone.actions.MailGroup
Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module Products.PDBDebugMode.runcall, line 70, in pdb_runcall
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.z3cform.layout, line 66, in __call__
  Module plone.z3cform.layout, line 60, in update
  Module z3c.form.form, line 281, in render
  Module z3c.form.form, line 163, in render
  Module Products.Five.browser.pagetemplatefile, line 125, in __call__
  Module Products.Five.browser.pagetemplatefile, line 59, in __call__
  Module zope.pagetemplate.pagetemplate, line 132, 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 171, in render
  Module 879080da5f9d96f4f246df32f37f1f88.py, line 93, in render
  Module 222df89141c79f8836d7108af238704e.py, line 1806, in render_titlelessform
  Module 222df89141c79f8836d7108af238704e.py, line 451, in render_fields
  Module 222df89141c79f8836d7108af238704e.py, line 126, in render_widget_rendering
  Module 222df89141c79f8836d7108af238704e.py, line 1069, in render_field
  Module five.pt.expressions, line 161, in __call__
  Module Products.Five.browser.metaconfigure, line 485, in __call__
  Module zope.browserpage.viewpagetemplatefile, line 83, in __call__
  Module zope.browserpage.viewpagetemplatefile, line 51, in __call__
  Module zope.pagetemplate.pagetemplate, line 132, 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 ced8c8ba0e04e0976df9799fdbb75fcb.py, line 591, in render
  Module ced8c8ba0e04e0976df9799fdbb75fcb.py, line 466, in render_widget_wrapper
  Module five.pt.expressions, line 161, in __call__
  Module plone.app.z3cform.widget, line 90, in render
  Module plone.app.widgets.base, line 178, in __init__
  Module plone.app.widgets.base, line 205, in _set_items
  Module lxml.etree, line 1031, in lxml.etree._Element.text.__set__ (src/lxml/lxml.etree.c:55347)
  Module lxml.etree, line 711, in lxml.etree._setNodeText (src/lxml/lxml.etree.c:24667)
  Module lxml.etree, line 699, in lxml.etree._createTextNode (src/lxml/lxml.etree.c:24516)
  Module lxml.etree, line 1439, in lxml.etree._utf8 (src/lxml/lxml.etree.c:32441)
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

 - Expression: "widget/@@ploneform-render-widget"
 - Filename:   ... rm-1.2.1-py2.7.egg/plone/app/z3cform/templates/macros.pt
 - Location:   (line 98: col 81)
 - Source:     ... place="structure widget/@@ploneform-render-widget"/>
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Expression: "widget/render"
 - Filename:   ... rm-1.2.1-py2.7.egg/plone/app/z3cform/templates/widget.pt
 - Location:   (line 38: col 46)
 - Source:     ... xt" tal:replace="structure widget/render"
                                              ^^^^^^^^^^^^^
 - Arguments:  repeat: {...} (0)
               context: <SelectWidget groups at 0xb17d79d0L>
               views: <ViewMapper - at 0xb1796910L>
               modules: <TraversableModuleImporter - at 0xb5dbe8b0L>
               args: <tuple - at 0xb6dde030L>
               nothing: <NoneType - at 0x23c8dc>
               target_language: <NoneType - at 0x23c8dc>
               default: <object - at 0xb6e05a18L>
               request: <instance - at 0xb3d95d50L>
               wrapped_repeat: {...} (0)
               loop: {...} (0)
               template: <ViewPageTemplateFile - at 0xb318e3b0L>
               translate: <function translate at 0xb0d5e4f0L>
               options: {...} (0)
               view: <RenderWidget ploneform-render-widget at 0xb1796370L>

The offending line is: https://github.com/plone/plone.app.widgets/blob/master/plone/app/widgets/base.py#L205

This looks very similar to #120 and #127, but I'm not sure if it's the same as either one.

I have: