KeyError in handleActionError for fields which in a form group

Bug #592453 reported by Maik Derstappen on 2010-06-10
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
z3c.form
Undecided
Unassigned

Bug Description

hi, if i try this in an form with groups, then i get an KeyError:

            raise interfaces.WidgetActionExecutionError(
                'email', zope.interface.Invalid('Invalid email address, address is already in use!')
            )

email is a widget which is in a group in the form:

class OnlineMemberSignupForm(group.GroupForm, form.EditForm):
    fields = field.Fields(IOnlineMemberSignupFormSchema)
    groups = (PrimaryContactGroup,)

i thing here is some thing wrong (handleActionError in form.py):

76: if isinstance(event.error, interfaces.WidgetActionExecutionError):
77: widget = event.action.form.widgets[event.error.widgetName]

event.action.form.widgets has no widgets of the groups, so looking in the groups would solve this.
But maybe there another solution, to have all widgets addressed to event.action.form.widgets?

This solved this problem temporary for me:

    widget = None
    if isinstance(event.error, interfaces.WidgetActionExecutionError):
        widget = event.action.form.widgets.get(event.error.widgetName)
        if not widget:
            for group in event.action.form.groups:
                widget = group.widgets.get(event.error.widgetName)
                if widget:
                    break

do i something wrong, or is this simply a bug?

Stephan Richter (srichter) wrote :

The ``handleActionError()`` event subscriber was written without groups in mind. And as all code in form.py, it should not handle groups correctly. A similar subscriber should be developed for ``IGroupForm`` implementations that takes groups into consideration as you outline in your workaround above.

The second step would be to make the current event handler resistant against widget lookup failures by catching the KeyError.

I would love to receive a patch for this.

Changed in z3c.form:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers