"Thomas B. Passin" wrote:
[Joseph A Knapka]
OK, I lied, Zope wasn't using the re-globalfied version, which still breaks. However, I've managed to narrow the problem down: The problem with global data being "missing" only happens when the DTML doc that calls my external method is invoked from a particular other DTML document.
Also, I discovered that if I create an empty module called "myGlobals", and explicitly place all my global data there, everything works. Still confused, trying to build a simple case that breaks the same way as my original code.
Well, in Python you can invoke any function with your own context (globals and locals). Zope may supply its own globals when it calls an external method , and maybe in some cases that would prevent yours from being known.
I thought of that, but it's still bizarre, because my code says: def myExtMethod(REQUEST): global req_data req_data = REQUEST ... and then later in code called from myExtMethod(), it's *req_data* that can't be found in the global namespace. Since it's being assigned at a place which every single call to this code passes through, I'm quite mystified. But it does seem to be an animal of the general nature you suggest.
It's an area I don't know much about. I'd still prefer to pass everything as explicit parameters, but I can see cases where it would be useful to use various global variables.
Sometimes globals are good. Sometimes even "goto" is good :)
How are you making use of your myGlobals module? Just importing * from it?
import myGlobals def myExtMethod(REQUEST): myGlobals.req_data = REQUEST ... ... then use "myGlobals.req_data" instead of just "req_data" everywhere else in the file. The problem definitely smells of some weird interaction between Zope and the Python namespace mechanism. I may just tear the hood off of Zope some time soon and poke around a bit. Cheers, -- Joe "I should like to close this book by sticking out any part of my neck which is not yet exposed, and making a few predictions about how the problem of quantum gravity will in the end be solved." --- Physicist Lee Smolin, "Three Roads to Quantum Gravity"