"Thomas B. Passin" wrote:
[Joseph A Knapka]
Since I'm checking to see whether REQUEST has a key 'xyz', and setting it if not, then by the time we get to the <dtml-var xyz> line, REQUEST definitely *does* have an 'xyz' key; and since REQUEST is undoubtedly in the namespace (right?), how can <dtml-var xyz> possibly result in a KeyError?
Sounds mysterious, all right. Let's get clear on a few things, then maybe Dieter or someone else will know the answer.
1) Is it the case that nothing else every happens on your page between the setting of the xyz property in the REQUEST and the <dtml-var xyz> rendering?
Nothing else happens within the document - I've put the <dtml-var xyz> immediately after the if/then/else block to be sure. However, the document containing the problematic code is being invoked by another. I suspect that may be an important fact, which I apologize for omitting from my original post.
2) When you say that you "sometimes" get an error, can you tell what has preceded it when you do and do not get an error?
That was a bit disingenuous of me :-) By "sometimes" I mean that in a particular bit of production code the problem occurs, but I haven't been able to reproduce the problem in a simple, postable-to-the-list case. I constructed a test case that is identical in form AFAICT: a document D1 is invoked as a request handler, and that document invokes a second document D2 that contains the code in question. That test case works fine.
3) Add a line after you assign the variable, like this:
<dtml-if expr="REQUEST.has_key('xyz')"> The property already exists, and its value is ==<dtml-var "REQUEST.xyz">==<br> <dtml-else> <dtml-call expr="REQUEST.set('xyz','Hello world')"> We just set the property<br> </dtml-if>
This will let you know if there is a property with that name whose value is empty, or whether it is in fact getting set. The "== ==" characters are ther to let you see if there is an empty string. It may seem obvious that it has to get set, but best to cover all possiblitites when strange things happen.
You could also add <dtml-var REQUEST> before and after to see whether the xyz property did get into the REQUEST after all.
Let us know the results.
Will do. Of course, as you've pointed out, it's not hard to work around the problem, and I've already done so, but I just want to understand what's really going on here. Software behaving in apparently mysterious ways does not inspire confidence :-) Thanks very much, -- 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"