collective / collective.elephantvocabulary

zope vocabulary with possibility to hide/show terms
http://pypi.python.org/pypi/collective.elephantvocabulary
GNU General Public License v2.0
1 stars 0 forks source link

Don't manipulate registry records by accident #6

Open lukasgraf opened 10 years ago

lukasgraf commented 10 years ago

In vocabulary.py:76 we've got

            if record and type(record) == list:
                if type(self.hidden_terms) == list:
                    self.hidden_terms.append(record)
                else:
                    self.hidden_terms = record

This means, on the last line self.hidden_terms gets replaced with a reference to the registry record. The next time we write to self.hidden_terms by appending to it, we actually modifiy the plone.app.registry record (which is supposed to be a read-only source for hidden / visible terms).

Also, because of the list-nesting described in #3 this will cause the registry record to become invalid, and therefore not editable any more through the p.a.registry UI:

Traceback (innermost last):

    Module ZPublisher.Publish, line 126, in publish
    Module ZPublisher.mapply, line 77, in mapply
    Module ZPublisher.Publish, line 46, in call_object
    Module plone.z3cform.layout, line 70, in __call__
    Module plone.z3cform.layout, line 54, in update
    Module plone.app.registry.browser.edit, line 24, in update
    Module z3c.form.form, line 208, in update
    Module plone.z3cform.patch, line 21, in BaseForm_update
    Module z3c.form.form, line 149, in update
    Module z3c.form.form, line 134, in updateWidgets
    Module z3c.form.field, line 275, in update
    Module z3c.form.browser.orderedselect, line 50, in update
    Module z3c.form.browser.widget, line 70, in update
    Module z3c.form.widget, line 200, in update
    Module z3c.form.widget, line 123, in update
    Module z3c.form.converter, line 297, in toWidgetValue
    Module z3c.form.term, line 34, in getTerm
    Module zope.schema.vocabulary, line 124, in getTerm

TypeError: unhashable type: 'list' 

Proposed fix: Only ever store values of a registry record, never the record itself.