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

ValueError: value or token must be provided (only one of those) #121

Closed
woolyseal opened this issue Nov 26, 2020 · 4 comments · Fixed by #122
Closed

ValueError: value or token must be provided (only one of those) #121

woolyseal opened this issue Nov 26, 2020 · 4 comments · Fixed by #122
Assignees

Comments

@woolyseal
Copy link
Member

Versionen:

Plone 5.2.0 (5207)
CMF 2.4.0
Zope 4.1.1
Python 3.7.5 (default, Nov 7 2019, 10:50:52) [GCC 8.3.0]
PIL 6.1.0 (Pillow)
WSGI: An
Server: waitress 1.3.0

AddOn I tested: python3-branch vom MasterSelectWidget (https://github.com/collective/plone.formwidget.masterselect)

Error got up as I tried to use the vocabulary_method to change another fields input.

2020-11-25 14:19:30,830 ERROR [Zope.SiteErrorLog:251][waitress] 1606310370.82950660.9245520262157388 http://localhost:8080/Plone/++add++HULSFPage/++widget++studyCourse Traceback (innermost last): Module ZPublisher.WSGIPublisher, line 155, in transaction_pubevents Module ZPublisher.WSGIPublisher, line 337, in publish_module Module ZPublisher.WSGIPublisher, line 243, in publish Module ZPublisher.BaseRequest, line 523, in traverse Module ZPublisher.BaseRequest, line 330, in traverseName Module zope.traversing.namespace, line 165, in namespaceLookup Module plone.z3cform.traversal, line 54, in traverse Module plone.dexterity.browser.add, line 141, in update Module plone.z3cform.fieldsets.extensible, line 65, in update Module plone.z3cform.patch, line 30, in GroupForm_update Module z3c.form.group, line 141, in update Module z3c.form.group, line 52, in update Module z3c.form.group, line 48, in updateWidgets Module z3c.form.field, line 277, in update Module plone.app.z3cform.widget, line 443, in update Module z3c.form.browser.text, line 36, in update Module z3c.form.browser.widget, line 171, in update Module Products.CMFPlone.patches.z3c_form, line 47, in _wrapped Module z3c.form.widget, line 132, in update Module plone.app.z3cform.converters, line 181, in toWidgetValue Module plone.app.vocabularies.principals, line 147, in getTerm Module plone.app.vocabularies.principals, line 113, in _get_term_from_source ValueError: value or token must be provided (only one of those)

@woolyseal
Copy link
Member Author

I will make a pull request shortly to fix/enhance this

@NicolasGoeddel
Copy link

NicolasGoeddel commented Nov 26, 2020

A few days ago I just stumbled upon the same issue. But I solved it in another way.
First it is kinda weird that so many widgets are updated if I just want to get the autocomplete values for one specific field.

My request looks like this:
http://localhost:8280//++add++stichtag/++widget++form.widgets.askId/@@getSource?query=&page_limit=10&page=1&_=1606242235986

In this request it seems that z3cform iterates over all the possible AjaxSelectWidgets and calls the update() method on them which seems unnecessary. It should only call update() on the Widget for the field askId. While it is iterating over the widgets it also finds it way to <AjaxSelectWidget 'form.widgets.IOwnership.creators'>. In this line it retrieves the value (None,) from the adapter. And therefore I change this line:


To this:

        if not value or value == (None,):
            return self.field.missing_value

I thought the best way would be to return the missing_value instead the exception. But maybe I am wrong.

The other thing is: I get a ValueError and not an AttributeError:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 359, in publish_module
  Module ZPublisher.WSGIPublisher, line 250, in publish
  Module ZPublisher.BaseRequest, line 518, in traverse
  Module ZPublisher.BaseRequest, line 329, in traverseName
  Module zope.traversing.namespace, line 165, in namespaceLookup
  Module plone.z3cform.traversal, line 54, in traverse
  Module ldkiid.base.browser.stichtag, line 40, in update
  Module plone.dexterity.browser.add, line 141, in update
  Module plone.z3cform.fieldsets.extensible, line 65, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 141, in update
  Module z3c.form.group, line 52, in update
  Module z3c.form.group, line 48, in updateWidgets
  Module z3c.form.field, line 277, in update
  Module plone.app.z3cform.widget, line 444, in update
  Module z3c.form.browser.text, line 36, in update
  Module z3c.form.browser.widget, line 171, in update
  Module Products.CMFPlone.patches.z3c_form, line 47, in _wrapped
  Module z3c.form.widget, line 132, in update
  Module plone.app.z3cform.converters, line 181, in toWidgetValue
  Module plone.app.vocabularies.principals, line 165, in getTerm
  Module plone.app.vocabularies.principals, line 130, in _get_term_from_source
ValueError: value or token must be provided (only one of those)

@woolyseal
Copy link
Member Author

Thank you for this information :) And for the note. You are totally right that it should be a ValueError not an AttributeError. I will change that in my Pullrequest!

@szakitibi
Copy link

szakitibi commented Feb 25, 2022

The original error is still there.

Steps to reproduce

  1. create a minimal plone buildout -> currently it is Plone 5.2.7
  2. add plone.formwidget.autocomplete to the eggs section of the buildout.cfg
  3. run bin/buildout and start instance bin/instance fg
  4. create a new Plone site, install AutocompleteWidget
  5. go to Site Setup / Dexterity Content Type and create a new type (keep default behaviors)
  6. go to Fields tab and open XML schema for edit, then add a basic Users list field with autocomplete:
<model xmlns:i18n="http://xml.zope.org/namespaces/i18n" xmlns:marshal="http://namespaces.plone.org/supermodel/marshal" xmlns:form="http://namespaces.plone.org/supermodel/form" xmlns:security="http://namespaces.plone.org/supermodel/security" xmlns:users="http://namespaces.plone.org/supermodel/users" xmlns:lingua="http://namespaces.plone.org/supermodel/lingua" xmlns:easyform="http://namespaces.plone.org/supermodel/easyform" xmlns="http://namespaces.plone.org/supermodel/schema">
  <schema>
    <field name="users" type="zope.schema.List">
     <form:widget type="plone.formwidget.autocomplete.AutocompleteMultiFieldWidget"/>
      <description/>
      <required>False</required>
      <title>Users</title>
      <value_type type="zope.schema.Choice">
        <vocabulary>plone.app.vocabularies.Users</vocabulary>
      </value_type>
    </field>
  </schema>
</model>

Searching for non existing user on the ++add++ form results:

2022-02-25 18:26:33,881 ERROR   [Zope.SiteErrorLog:252][waitress-2] 1645809993.88086990.7493304168826274 http://localhost:8080/Plone/++add++test/++widget++form.widgets.users
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 371, in publish_module
  Module ZPublisher.WSGIPublisher, line 250, in publish
  Module ZPublisher.BaseRequest, line 518, in traverse
  Module ZPublisher.BaseRequest, line 329, in traverseName
  Module zope.traversing.namespace, line 165, in namespaceLookup
  Module plone.z3cform.traversal, line 54, in traverse
  Module plone.dexterity.browser.add, line 138, in update
  Module plone.z3cform.fieldsets.extensible, line 65, in update
  Module plone.z3cform.patch, line 30, in GroupForm_update
  Module z3c.form.group, line 141, in update
  Module z3c.form.group, line 52, in update
  Module z3c.form.group, line 48, in updateWidgets
  Module z3c.form.field, line 277, in update
  Module plone.app.z3cform.widget, line 444, in update
  Module z3c.form.browser.text, line 36, in update
  Module z3c.form.browser.widget, line 171, in update
  Module Products.CMFPlone.patches.z3c_form, line 47, in _wrapped
  Module z3c.form.widget, line 132, in update
  Module plone.app.z3cform.converters, line 181, in toWidgetValue
  Module plone.app.vocabularies.principals, line 165, in getTerm
  Module plone.app.vocabularies.principals, line 130, in _get_term_from_source
ValueError: value or token must be provided (only one of those)

As it is pointed out in https://github.com/NicolasGoeddel's #121 (comment) the (None, ) value results the error.

There is also a quite nice summary on the reasons behind it plone/plone.app.dexterity#311 (comment). The best fix seems to be the (None, ) check in plone.app.z3cform.converters.AjaxSelectWidgetConverter.toWidgetValue.

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

Successfully merging a pull request may close this issue.

3 participants