Discussion:
[Erp5-dev] external methods seems to not keep the calling context
Morin Fabien
2007-12-28 16:13:14 UTC
Permalink
Hello,
I have a very strange error :
an ExternalMethod is called with **kw parameters, and I have the
following TypeError :
ERP5Site_createModuleScribus() takes at least 1 non-keyword argument (0
given)
this append in Base_callDialogMethod.py on line 201 :
return dialog_form(**kw)
where dialog_form is an external method with the following prototype :
def createModuleScribus(self, form_id=None, module_portal_type=None,
portal_skins_folder=None, object_portal_type=None, object_title=None, module_id=None,
module_title=None, selection_index=None, selection_name=None, import_scribus_file=None,
import_pdf_file=None, option_html=None,desired_height=None, desired_width=None, import_image_1=None, import_image_2=None,
import_image_3=None, **kw) :

The error disapear if the dialog_form is called like this : return
dialog_form(context, **kw)

According to the external method doc string, pass context is not
mandatory, so it's quite strange...


Any Idea ?


I'm using
Zope Version : (Zope 2.8.9.1-final, python 2.4.4, linux2)
Python Version : 2.4.4 (#2, Oct 20 2007, 22:07:32) [GCC 4.1.2 20070302
(prerelease) (4.1.2-1mdv2007.1)]


Fabien
-------------- next part --------------
"""Call an ExternalMethod

Calling an External Method is roughly equivalent to calling
the original actual function from Python. Positional and
keyword parameters can be passed as usual. Note however that
unlike the case of a normal Python method, the "self" argument
must be passed explicitly. An exception to this rule is made
if:

- The supplied number of arguments is one less than the
required number of arguments, and

- The name of the function\'s first argument is 'self'.

In this case, the URL parent of the object is supplied as the
first argument.
Pelletier Vincent
2007-12-28 17:36:29 UTC
Permalink
Hi.

For the ones (including me, at first sight) who don't get the big picture:

The code from Base_callDialogMethod[1] tries to invoke
ERP5Site_createModuleScribus, an external method, using the following code,
simplified:

# kw contains values fetched from a submited form
# dialog_method = "ERP5Site_createModuleScribus"
dialog_form = getattr(context, dialog_method)
return dialog_form(**kw)

The problem is that the call fails with the error message reported by Fabien.
Of course, this call is correct for usual cases where dialog_form is a regular
script, so this call should not need to be changed.
As dialog_form is wrapped in acquisition context, it should not need to be
explicitely passed to external method.

http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_callDialogMethod.xml
--
Vincent Pelletier
Loading...