Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mtrebron opened this issue May 30, 2023 · 1 comment

Comments

@mtrebron
Copy link

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>

@jaroel
Copy link
Member

jaroel commented Jun 6, 2023

The self.context is not None check in zopefoundation/zope.schema@59f7eca#diff-ffc7d7c0103fcee651dcc261e613b900e01fd71be01ba9f22e30953741a9670fR402-R403 is surfacing the problems in DGF. This is not a problem in zope.schema imho, because the right context is somewhere, just not passed along correctly.

Somehow self.context is None in the nested DGF instead of {} like it is a few frames up.

If the actual context isn't needed because wants to populate a vocab based on an external datasource, we can use a IVocabularyFactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants