[ATT] "InstanceDict" (and thereby) the DTML namespace are caching was: [Zope] Why doesn't setting REQUEST keys work inside <dtml-with REQUEST> ?

Dieter Maurer dieter@handshake.de
Sat, 6 Apr 2002 11:34:43 +0200


Don Hopkins recently found that "REQUEST.set" does not work as
expected inside "<dtml-with REQUEST>".


I replied:
 > Don Hopkins writes:
 >  > ... wrong value shown inside "<dtml-with REQUEST>" ...
 > 
 > I have a work around for you:
 > 
 >   <dtml-with REQUEST mapping>
 > 
 > will work as expected.
 > 
 > 
 > However, I do not understand this behaviour:
 > 
 >    The difference between "<dtml-with REQUEST>" and
 >    "<dtml-with REQUEST mapping>" is that in the first
 >    case "REQUEST" is wrapped into an "InstanceDict" before
 >    it is pushed onto the namespace while in the second case
 >    it is pushed itself (unwrapped).
 > 
 >    "InstanceDict" is a wrapper that maps "getitem" onto the
 >    wrapped object's "getattr".
 > 
 >    But, because "REQUEST" maps its "getattr" to its "getitem",
 >    there should not be a big difference.
 >    Should, as you see there is one....

I now do understand the behaviour:

  "InstanceDict" instances are caching the values they returned!

  This has wide ramifications, for example:

    *  "REQUEST.set" apparently ineffective inside "dtml-with REQUEST"
       (as Don found out)

    *  modifications to properties apparently ineffective



I am no longer sure, I should consider this a bug (as I did in the
previous message).
But at least, it requires a big warning sign in the Zope book
and other DTML related documentation.
That's the reason, I send this message to you, too, Chris.


Dieter