Ticket #12031 (confirmed Bug)

Opened 5 years ago

Last modified 4 years ago

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

Change History

comment:1 in reply to: ↑ description Changed 5 years ago by datakurre

Or as my workmate noticed, instead of just copying, one could also make the method cleaner...

def query(self, default=interfaces.NO_VALUE):
    """See z3c.form.interfaces.IDataManager"""
    try:
        return self.get()
    except AttributeError:
        return default

...and maybe even fix the "get"-method to raise AttributeError when necessary for "query" to return the given default value.

comment:2 Changed 4 years ago by kleist

  • Component changed from Unknown to Infrastructure

comment:3 Changed 4 years ago by kleist

  • Status changed from new to confirmed
  • Keywords z3c.formrelationfield added; z3c.form relationfield removed
  • Version set to 4.2
  • Milestone changed from 4.2 to 4.x

comment:4 Changed 4 years ago by davisagli

  • Component changed from Infrastructure to General

comment:5 Changed 4 years ago by datakurre

  • Description modified (diff)
Note: See TracTickets for help on using tickets.