Ticket #12031 (confirmed Bug)
RelationDictDataManager lacks "query"-method (and mediates RelationValues to widgets)
Reported by: | datakurre | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 4.x |
Component: | General | Version: | 4.2 |
Keywords: | z3c.formrelationfield | Cc: |
Description (last modified by datakurre) (diff)
Regarding plone.app.relationfield.widget.RelationDictDataManager (trunk).
http://svn.plone.org/svn/plone/plone.app.relationfield/trunk/plone/app/relationfield/widget.py
RelationDictDataManager is inherited from z3c.form's default DictionaryField, but doesn't implement its own "query"-method.
When z3c.form uses IDataManager's "query"-method for reading/converting field data to widget, DictionaryField's "optimized" query-implementation gets called and raw RelationValue is being returned to widget (instead of related object). This breaks forms editing dictionaries with relations.
This could be fixed by implementing "query" directly on RelationDictDataManager by e.g. copying working implementation from z3c.form.datamanager.AttributeField:
def query(self, default=interfaces.NO_VALUE): """See z3c.form.interfaces.IDataManager""" try: return self.get() except ForbiddenAttribute, e: raise e except AttributeError: return default
Or as my workmate noticed, instead of just copying, one could also make the method cleaner...
...and maybe even fix the "get"-method to raise AttributeError when necessary for "query" to return the given default value.