[Zope] attribute error: absolute_url
marc lindahl
marc@bowery.com
Mon, 18 Jun 2001 12:10:51 -0400
> From: Casey Duncan <cduncan@kaivo.com>
> Organization: Kaivo, Inc. (www.kaivo.com)
> Date: Mon, 18 Jun 2001 09:53:11 -0600
> To: Dieter Maurer <dieter@handshake.de>
> Cc: "wazum-mail (wolfgang)" <wolfgang@wazum.com>, zope@zope.org
> Subject: Re: [Zope] attribute error: absolute_url
>
> Dieter Maurer wrote:
>>
>> wazum-mail (wolfgang) writes:
>>> ...
>>> <dtml-if text_css_styles><link rel="stylesheet" type="text/css"
>>> href="<dtml-var "text_css_styles.absolute_url ()">"></dtml-if>
>>> ...
>>> AttributeError: absolute_url
>> That's a nasty side effect of the caching performed by
>> many DTML tags:
>>
>> If you use "<dtml-if name=XXX ...>" (this is the explicit
>> form of "<dtml-if XXX ...>"),
>> then "XXX" is rendered and bound to the name "XXX".
>> When you later access "XXX", you get the already rendered
>> value.
>>
>> If "XXX" is (originally) bound to a DTML object (as in your case),
>> then it is very likely that its rendered value is a string
>> which (of course) does not have an "absolute_url" method.
>>
>> Dieter
>>
>
> Smells like a bug to me. IMHO caching should be entirely transparent to
> the top-level behavior. But alas, our world is less than perfect.
>
> I'm surprised I haven't run into this myself...
I ran into this type of thing in CMF when they added a __call__ to
Document.py... Here's the reply I got:
> On Thu, 31 May 2001, marc lindahl wrote:
>
>> Hey, that was it!! I wonder why the behaviour changed? Some new fancy
>> caching going on somewhere?
>
> Believe it or not, that particular caching has been there for a long time
> now. It has always bothered me but I didn't know why, and now I know why.
> :-) This specific case could be corrected, though.
>
> This happened because Document now has a __call__() method. It didn't
> before.
>
>> So what would I use for the if? Something ugly like "_.hasattr('bio')" ?
>
> I would try <dtml-if expr="_.getitem('bio', 0)">. Ugly but it works.
> ZPT, which is coming along very well, is designed from the start to
> provide clean alternatives to expressions like that.
>
> Shane
>
>