@action decorator overrides actions of superclasses
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 3 |
Won't Fix
|
Undecided
|
Unassigned | ||
zope.formlib |
Invalid
|
Undecided
|
Unassigned |
Bug Description
That seems to be because the @action decorator uses sys._getframe() to get the caller's .actions attribute and append the new Action instance to it. When it does that for any class whose superclass uses the @action decorator, it doesn't find an .actions attribute defined and thus assigns an empty Actions object to it. From there you know what happens: the superclass' @action methods will not be present in my class' .actions attribute and thus they won't be rendered/processed.
In the following example, I'd like instances of MyForm2 to have both the 'Save' and 'Edit' actions, but it doesn't.
from zope.formlib import form
from zope import interface, schema
class IOrder(
identifier = schema.
class MyForm(form.Form):
form_fields = form.Fields(IOrder, render_
@form.
def edit_action(self, action, data):
pass
class MyForm2(MyForm):
@form.
def save_action(self, action, data):
pass
print [action.label for action in MyForm2(None, None).actions]
['Save']
Changed in zope3: | |
status: | New → Won't Fix |
formlib already depends on zope.interface, so there is no dependency related reason not to use zope.interface. advice instead of sys._getframe(). That'd allow merging of actions from base class(es).