"ValueError: term values must be unique" error when editing page (Plone 5.2)

I've been doing a lot of work on our site today, almost entirely concerned with modifying CSS. The most recent changes I made were simply changing a bunch of font colours.

Now, when I attempt to edit any page (or add a new page), I receive the following error:

Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 155, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 337, in publish_module
  Module ZPublisher.WSGIPublisher, line 255, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 61, in call_object
  Module plone.z3cform.layout, line 63, in __call__
  Module plone.z3cform.layout, line 47, in update
  Module plone.dexterity.browser.edit, line 58, 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 176, in toWidgetValue
  Module plone.app.z3cform.widget, line 399, in get_vocabulary
  Module plone.app.vocabularies.principals, line 235, in __call__
  Module zope.schema.vocabulary, line 128, in __init__
ValueError: term values must be unique: 'ika'

"ika", in the last line, may refer to the username of a test user that I've been logging in as, but is not the username I'm currently logged in as when I receive the error, nor has that user edited or created any pages. (They're the user I use to test what the site looks like to someone who can login but has no other permissions.)

All of the changes I was making to the site prior to this error appearing were constrained to the theme I'm working on, so I tried switching back to Barceloneta, but I still receive the same error.

Problem disappeared after update to Plone 5.2.1. shrug

Hi @irfon

Can you please report back in case it does resurface? I am having (had, see workaround below) this happen "randomly" on a Plone 5.0.x intranet where the field in question is in a TTW Dexterity content type. Both on display and edit view. The ValueError is thrown on the first value in the dictrionary.

    <field name="land" type="zope.schema.Choice">
      <default>DEU</default>
      <description/>
      <required>True</required>
      <title>Country</title>
      <vocabulary>my_theme.CountryList</vocabulary>
      <swallow_duplicates>True</swallow_duplicates>
    </field>

After reading here: https://zopeschema.readthedocs.io/en/latest/fields.html

By default, ValueErrors are thrown if duplicate values or tokens are passed in.
If you are using this vocabulary as part of a form that is generated from
non-pristine data, this may not be the desired behavior. If you want to swallow
these exceptions, pass in swallow_duplicates=True when initializing the
vocabulary.

and inserting the <swallow_duplicates /> tag, The traceback has not appeared again. However, I'm sure the problem did not just suddenly go away.

Before adding the element, the issue would surface occasionally after restarting my zeocluster (2 local and 1 remote client instance). When the issue appeared, a new restart would most often (cough) fix it...

The vocabulary is defined as follows, and I would bet that the data is indeed "pristine"

import pycountry
class CountryVocabulary(object):
    grok.implements(IVocabularyFactory)
    def __call__(self, context):
        terms = [
            SimpleTerm(value=country.alpha3, token=country.alpha3, title=country.name)
            for country in pycountry.countries]
        return SimpleVocabulary(terms)

grok.global_utility(CountryVocabulary,
                    name=u'my_theme.CountryList')

PS the title of your post does not describe the problem very well.

Completely fair. I've been running into a LOT of issues lately and I think I was running out of steam by this time. :slight_smile: I will be more diligent in future.

If it helps your information gathering, the site on which I encountered this has had no custom fields or content types added.

1 Like

Cheers. Yes it validates my assumption that the ValueError being thrown is not caused by having actual duplicate values in a vocabulary. In your case, it probably choked on the creators/contributors field.

As the original poster, I think you would see an edit icon next to the title. No biggie, good luck!

Plone Foundation Code of Conduct