Different external method and acquisition syntax question.
Hi All, I can't seem to find an answer to my external method and acquisition syntax question so here goes: I have three objects: python script(alpha) -> external method(beta) -> zsql(delta) The python script "alpha" is in subfolder "/proj/py_script". The external method "beta" is in subfolder "/proj/ex_python". the zsql object "delta" is in subfolder "/proj/db". The python script "alpha" is invoked and calls: context.ex_python.beta() External method "beta" is fired up and calls: self.db.delta() Which results in a runtime error of: Error Type: AttributeError Error Value: db I've tried moving zsql object "delta" into the "/proj/ex_python" subfolder and changed the code in external method "beta" to read self.delta() Which resulted in a runtime error of: Error Type: AttributeError Error Value: delta Any ideas? Thanks, Jelle --
jelle writes:
I can't seem to find an answer to my external method and acquisition syntax question so here goes:
I have three objects:
python script(alpha) -> external method(beta) -> zsql(delta)
The python script "alpha" is in subfolder "/proj/py_script". The external method "beta" is in subfolder "/proj/ex_python". the zsql object "delta" is in subfolder "/proj/db".
The python script "alpha" is invoked and calls:
context.ex_python.beta()
External method "beta" is fired up and calls:
self.db.delta() Hm, strange!
It appears as if "self" would not be what you (and I) expect! We both expect it to be "proj.py_script.ex_python". But this, of course, has a "db" attribute. I would try to pass it explicitely, because the rules for passing "self" automatically are magical... context.ex_python.beta(context) If this should not work or you are curious, Shane has a very nice small External Method that allows to analyse the acquisition structure of an object: "showaq" (search the searchable mailing list archives). Dieter
I can't reproduce this with Zope 2.3.3. I have: py_script/alpha: # python script: return context.ex_python.beta() ex_python/beta: # external method calling: def beta(self): return self.db.delta() db/delta: # python script: return 'delta here' All works ok. I didn't use a zsql method here, so maybe that is the problem ? Regards, Florent Guillaume Nuxeo
Hello Florent and Dieter, Thanks for the reference to showaq and the test case. The test case provided by Florent works well on 2.4.0. also which forced me to refine my problem. Only python scripts and external methods where used instead of zsql object to simplify the latest test. The following fails when I pass a parameter to the external method with the message Error Type: AttributeError Error Value: util File Zope-2.4.0/Extensions/ex_test.py, line 2, in ex_test The invocation URL is http://localhost:8080/test/dev/alpha/py_alpha The sequence should be py_alpha -> py_beta -> ex_test -> py_delta. /test/util/ex_test #external method calling a python script def ex_test(self,param=''): return ' ex_test ' + self.util.py_delta() /test/util/py_delta #python script return ' delta ' /test/dev/alpha/py_alpha #python script calling a python script return ' py_alpha ' + context.beta.py_beta() /test/dev/master/beta/py_beta #python script calling an external method return ' py_beta ' + context.util.ex_test('boing') However changing the contents of py_beta to return ' py_beta ' + context.util.ex_test() succeeds returning "alpha beta ex_test gamma" as expected. Note the absence of a parameter passed to external method ex_test from py_beta. Is there something I'm missing? Thanks, Jelle
jelle writes:
#external method calling a python script def ex_test(self,param=''): return ' ex_test ' + self.util.py_delta()
/test/util/py_delta #python script return ' delta '
/test/dev/alpha/py_alpha #python script calling a python script return ' py_alpha ' + context.beta.py_beta()
/test/dev/master/beta/py_beta #python script calling an external method return ' py_beta ' + context.util.ex_test('boing') That's easy to explain: the magic of automatic "self" passing hits you:
External Method passes "aq_parent" automatically as first parameter provided both of the following conditions are met: 1. the first parameter is named "self" 2. the number of provided parameters is one less than the number of mandatory parameters. In your case, the number of mandatory parameters is 1 and you pass one argument 'boing'. That means, "self" is not passed automatically. It gets the value "boing", which has no attributes, of course. Dieter
Hi Dieter, Hurrah! On Wed, 8 Aug 2001, Dieter Maurer wrote:
jelle writes:
#external method calling a python script def ex_test(self,param=''): return ' ex_test ' + self.util.py_delta()
[ snippedĀ ]
2. the number of provided parameters is one less than the number of mandatory parameters.
The changed external method works. def ex_test(self,param, dummy='dummy'): return ' ex_test ' + str(param) + self.util.py_delta() This is a much easier change than I feared. Much thanks, Jelle
participants (3)
-
Dieter Maurer -
Florent Guillaume -
jelle