What's wrong with the 'getattr' call in this DTML method? I get an error message: "Name not found or not allowed undefined." (using ZDebug). (The problem is not the choice of attribute names -- I get it whatever I type that isn't an attribute in the REQUEST.) If I arrange to get into pdb from this method, the getattr expression works fine. Is this a Zope bug? _____________________________________________________________________ <html> <body> REQUEST does <dtml-if expr="not _.hasattr(REQUEST,'undefined')"> not </dtml-if> have the attribute 'undefined'. <p> value = <dtml-var expr="_.getattr(REQUEST, 'undefined', 'nothing')"> </body> </html> _____________________________________________________________________
On Monday 29 October 2001 08:26 am, Mitch Model allegedly wrote:
What's wrong with the 'getattr' call in this DTML method? I get an error message: "Name not found or not allowed undefined." (using ZDebug). (The problem is not the choice of attribute names -- I get it whatever I type that isn't an attribute in the REQUEST.) If I arrange to get into pdb from this method, the getattr expression works fine. Is this a Zope bug?
_____________________________________________________________________ <html> <body> REQUEST does <dtml-if expr="not _.hasattr(REQUEST,'undefined')"> not </dtml-if> have the attribute 'undefined'. <p> value = <dtml-var expr="_.getattr(REQUEST, 'undefined', 'nothing')"> </body> </html> _____________________________________________________________________
Calling hasattr on REQUEST is not allowed from DTML, and is not necessary. Try using has_key instead, as in: <dtml-if expr="REQUEST.has_key('whatever')"> To get the desired default value behavior, user REQUEST.get: value = <dtml-var expr="REQUEST.get('somevar', 'nothing')"> hth, /---------------------------------------------------\ Casey Duncan, Sr. Web Developer National Legal Aid and Defender Association c.duncan@nlada.org \---------------------------------------------------/
Mitch Model <model@mpi.com> (by way of Mitchell Model) writes:
What's wrong with the 'getattr' call in this DTML method? I get an error message: "Name not found or not allowed undefined." (using ZDebug). (The problem is not the choice of attribute names -- I get it whatever I type that isn't an attribute in the REQUEST.) If I arrange to get into pdb from this method, the getattr expression works fine. Is this a Zope bug?
_____________________________________________________________________ <html> <body> REQUEST does <dtml-if expr="not _.hasattr(REQUEST,'undefined')"> not </dtml-if> have the attribute 'undefined'. <p> value = <dtml-var expr="_.getattr(REQUEST, 'undefined', 'nothing')"> </body> </html> _____________________________________________________________________ "_.getattr" does not work with "REQUEST", because "REQUEST" is primarily a mapping and does only expose its items as attributes, too. More precisely, its "__getattr__" (which is called by "_.getattr") is mapped to "REQUEST"'s "__getitem__" and this raises "KeyError" instead on "AttributeError". But "_.getattr" only catches "AttributeError" and propagates "KeyError".
I think this is a bug in "ZPublisher.BaseRequest.BaseRequest". It should map "__getitem__"'s "KeyError" into "__getattr__"'s "AttributeError". Would you like to write a tracker item? Dieter
participants (3)
-
Casey Duncan -
Dieter Maurer -
Mitch Model