Skip to content

InvalidVocabularyError when using nested DGF field with Choice field and IContextSourceBinder #165

@mtrebron

Description

@mtrebron

As far as I can understand this: the binding fails in https://github.com/collective/collective.z3cform.datagridfield/blob/master/src/collective/z3cform/datagridfield/row.py#L58 when DataGridFieldObjectWidget super in updateWidgets() https://github.com/collective/collective.z3cform.datagridfield/blob/master/src/collective/z3cform/datagridfield/datagridfield.py#L266 tries to update the terms of the SequenceWidget in https://github.com/zopefoundation/z3c.form/blob/master/src/z3c/form/widget.py#L229

See also: https://community.plone.org/t/icontextsourcebinder-in-datagridfield-leads-to-invalidvocabularyerror-in-zope-schema-field/17481

Reading https://zopeschema.readthedocs.io/en/latest/sources.html#sources-in-fields:

"If a IContextSourceBinder is passed as the source argument to Choice, it’s bind method will be called with the context as its only argument. The result must implement ISource and will be used as the source."

my "gut feeling" is that the way binding takes place in row.py is not always correct...

Using the same field and source in the main form works as expected.

ERROR   [Zope.SiteErrorLog:17][waitress-0] InvalidVocabularyError: http://localhost:8888/Plone/api/edi-order
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 Products.PDBDebugMode.wsgi_runcall, line 60, in pdb_runcall
  Module Shared.DC.Scripts.Bindings, line 333, in __call__
  Module Shared.DC.Scripts.Bindings, line 370, in _bindAndExec
  Module Products.PythonScripts.PythonScript, line 338, in _exec
  Module script, line 16, in edi-order
   - <PythonScript at /Plone/api/edi-order>
   - Line 16
  Module z3c.form.form, line 233, in __call__
  Module pnz.erpediem.client.browser.create_edi_order, line 345, 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 132, in update
  Module z3c.form.form, line 136, in updateWidgets
  Module z3c.form.field, line 274, in update
  Module z3c.form.browser.multi, line 63, in update
  Module z3c.form.browser.widget, line 171, in update
  Module z3c.form.widget, line 509, in update
  Module Products.CMFPlone.patches.z3c_form, line 46, in _wrapped
  Module z3c.form.widget, line 132, in update
  Module z3c.form.widget, line 504, in value
  Module collective.z3cform.datagridfield.datagridfield, line 154, in updateWidgets
  Module collective.z3cform.datagridfield.datagridfield, line 126, in getWidget
  Module z3c.form.browser.widget, line 171, in update
  Module z3c.form.object, line 297, in update
  Module collective.z3cform.datagridfield.datagridfield, line 267, in updateWidgets
  Module z3c.form.object, line 222, in updateWidgets
  Module z3c.form.object, line 216, in setupWidgets
  Module z3c.form.field, line 274, in update
  Module z3c.form.browser.multi, line 63, in update
  Module z3c.form.browser.widget, line 171, in update
  Module z3c.form.widget, line 509, in update
  Module Products.CMFPlone.patches.z3c_form, line 46, in _wrapped
  Module z3c.form.widget, line 132, in update
  Module z3c.form.widget, line 504, in value
  Module collective.z3cform.datagridfield.datagridfield, line 148, in updateWidgets
  Module z3c.form.widget, line 445, in updateWidgets
  Module collective.z3cform.datagridfield.datagridfield, line 126, in getWidget
  Module z3c.form.browser.widget, line 171, in update
  Module z3c.form.object, line 297, in update
  Module collective.z3cform.datagridfield.datagridfield, line 267, in updateWidgets
  Module z3c.form.object, line 222, in updateWidgets
  Module z3c.form.object, line 216, in setupWidgets
  Module z3c.form.field, line 274, in update
  Module z3c.form.browser.select, line 51, in update
  Module z3c.form.browser.widget, line 171, in update
  Module z3c.form.widget, line 233, in update
  Module z3c.form.widget, line 225, in updateTerms
  Module zope.component._api, line 102, in getMultiAdapter
  Module zope.component._api, line 116, in queryMultiAdapter
  Module zope.interface.registry, line 364, in queryMultiAdapter
  Module zope.interface.adapter, line 844, in queryMultiAdapter
  Module z3c.form.term, line 108, in ChoiceTerms
  Module zope.schema._field, line 458, in bind
  Module zope.schema._field, line 448, in _resolve_vocabulary
zope.schema._field.InvalidVocabularyError: Invalid vocabulary <pnz.erpediem.core.vocabularies.edifact.sources.ItalianCitiesSourceBinder object at 0x7f59c87de040>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions