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

Field using StaticCatalogVocabulary with AjaxSelectFieldWidget raises AttributeError on nonexisting value #70

Open
pbauer opened this issue May 13, 2022 · 1 comment · May be fixed by #71

Comments

@pbauer
Copy link
Member

pbauer commented May 13, 2022

When a content item that was stored in a schema.List field with AjaxSelectFieldWidget and a StaticCatalogVocabulary as vocabulary a missing content item raises:

AttributeError: http://localhost:8080/paediatrics/Plone/team/@@edit
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 376, in publish_module
  Module ZPublisher.WSGIPublisher, line 271, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module Products.PDBDebugMode.wsgi_runcall, line 60, in pdb_runcall
  Module plone.z3cform.layout, line 63, in __call__
  Module plone.z3cform.layout, line 47, in update
  Module plone.dexterity.browser.edit, line 55, 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 274, in update
  Module plone.app.z3cform.widget, line 441, 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 46, in _wrapped
  Module z3c.form.widget, line 132, in update
  Module plone.app.z3cform.converters, line 203, in toWidgetValue
AttributeError: 'NoneType' object has no attribute 'token'

Field example (basically the same as https://github.com/collective/example.contenttype/blob/master/src/example/contenttype/example.py#L660):

myfield = schema.List(
    title="My field"
    value_type=schema.Choice(
        vocabulary=StaticCatalogVocabulary({'portal_type': 'mytype'})),
    required=False,
    default=[],
)
directives.widget(
    'myfield',
    AjaxSelectFieldWidget,
    vocabulary=StaticCatalogVocabulary({'portal_type': 'mytype'})
)

The contract of ITerm says thai getTerm (called intoWidgetValue) it should instead raise a LookupError which can bei either ignored by the DataCoverter or shown.

pbauer added a commit that referenced this issue May 13, 2022
…ntract of ITerms.getTerm. The Error is handled in DataConverter. See #70
@pbauer pbauer linked a pull request May 13, 2022 that will close this issue
@pbauer
Copy link
Member Author

pbauer commented May 13, 2022

I'm not 100% sure if this is the right solution but with the change in #71 only the uuid is displayed when editing:

edit

When saving again a validation-error is shown ("Wrong type for container") which seems correct I think.
But a general question raises it's head here: How do we handle values from vocabularies stored in fields that are no longer valid because these values (be it content or other options) are not longer available?

@pbauer pbauer changed the title StaticCatalogVocabulary with AjaxSelectFieldWidget raises AttributeError on nonexisting value Field using StaticCatalogVocabulary with AjaxSelectFieldWidget raises AttributeError on nonexisting value May 13, 2022
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

Successfully merging a pull request may close this issue.

1 participant