[Zope] DTML namespace puzzle

Dieter Maurer dieter@handshake.de
Mon, 29 Jan 2001 19:17:27 +0100 (CET)


Ron Bickers writes:
 > method(num=num SESSION=session):
 >   <dtml-with "SESSION['INFO']" mapping>
 >     <dtml-var num>
 >   </dtml-with>
 > raises KeyError "num".
 > ....
 > SESSION['info'] does not have a key "num".  The only num is passed as a
 > parameter.  Did you use SQLSession to try to reproduce it, or just another
 > mapping?  Could SQLSession have something to do with it?
No, I did not use SQLSession but used a normal dictionary.

However, nothing should be able to hide "num" in the way you described.

   The DTML namespace is a stack of mappings.
   When the method is called, the keyword parameter dict is pushed onto
     this stack.
   The <dtml-with> pushes "SESSION['INFO']" onto the stack.

   When "num" is looked up, the namespace asks each mapping
   on the stack (from top to bottom) whether it knows
   "num". The first that does, wins.

The only thing, I could imagine, were that "SESSION['INFO']"
contained a num, but the user does not have access to its
value. However, this is incompatible with your observation
that:

  <dtml-let num=num>
    <dtml-with "SESSION['INFO']" mapping>
      <dtml-var num>
    </dtml-with>
  </dtml-let>

worked. The only difference between the two pieces of code
is that the working code as an additional mapping between
the keyword parameter dict and the "dtml-with" dict.
It appears as if some magic would pop a frame from the
namespace stack. SQLSession can't do it as it does not get hold
of the namespace. "dtml-with" could but it is very strange
that it should do such things and especially that it does
for you but not for me.


Dieter