collective / collective.z3cform.datagridfield

Datagrid Field for z3c.forms
https://pypi.org/project/collective.z3cform.datagridfield/
8 stars 28 forks source link

DictRow with Choice: ConstraintNotSatisfied #160

Closed krissik closed 1 year ago

krissik commented 1 year ago

I have a controlpanel with a DictRow that uses a schema with a choice field:

class IConfigExample(Interface):
    name = schema.TextLine(title=u'a simple TextLine')

    a_choice = schema.Choice(
        title=u'please choose your favorite number',
        vocabulary=SimpleVocabulary.fromValues(
            ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
        ),
    )

class IControlPanelExample(Interface):

    config_list = schema.List(
        title='Configuration',
        value_type=DictRow(title=u'tablerow', schema=IConfigExample),
        default=[{'name': 'test', 'a_choice': 'seven'}],
    )

After update to Plone6 I get an error while saving the control_panel:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 181, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 390, in publish_module
  Module ZPublisher.WSGIPublisher, line 285, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 68, in call_object
  Module plone.z3cform.layout, line 61, in __call__
  Module plone.z3cform.layout, line 45, in update
  Module plone.z3cform.fieldsets.extensible, line 62, in update
  Module plone.z3cform.patch, line 31, in GroupForm_update
  Module z3c.form.group, line 145, in update
  Module plone.app.z3cform.csrf, line 21, in execute
  Module z3c.form.action, line 98, in execute
  Module z3c.form.button, line 301, in __call__
  Module z3c.form.button, line 159, in __call__
  Module plone.app.registry.browser.controlpanel, line 60, in handleSave
  Module z3c.form.group, line 114, in applyChanges
  Module z3c.form.form, line 51, in applyChanges
  Module z3c.form.datamanager, line 91, in set
  Module plone.registry.recordsproxy, line 60, in __setattr__
  Module plone.registry.registry, line 51, in __setitem__
  Module plone.registry.record, line 82, in _set_value
  Module zope.schema._bootstrapfields, line 295, in validate
  Module zope.schema._field, line 772, in _validate
zope.schema._bootstrapinterfaces.WrongContainedType: ([ConstraintNotSatisfied(('six',), 'a_choice')], 'value')

value is a tuple (e.g. ('six',)) which can not be successfully valided. Maybe this is the reason for the tuple: https://github.com/zopefoundation/z3c.form/blob/master/src/z3c/form/widget.py#L245

I have collective.z3cform.datagridfield 3.0.0 and Plone 6.0.3.

How can I work around or fix this issue?

petschki commented 1 year ago

This should be fixed here https://github.com/collective/collective.z3cform.datagridfield/pull/142 ... though its not released.

petschki commented 1 year ago

I've just released 3.0.1 with this fix.