[Twisted-web] [Nevow] childFactory being called more than once
manlio_perillo at libero.it
Wed Feb 21 05:19:55 CST 2007
Valentino Volonghi aka Dialtone ha scritto:
> On Wed, 21 Feb 2007 11:19:41 +0100, Manlio Perillo
> <manlio_perillo at libero.it> wrote:
>> Just forget it!
>> I have a personalized locateChild in the base class, where I do:
>> def locateChild(self, ctx, segments):
>> request = inevow.IRequest(ctx)
>> if request.args.get('login-failure'):
>> import login
>> return login.Login(self.avatar, failure=True), ''
>> res = rend.Page.locateChild(self, ctx, segments)
>> if res == rend.NotFound:
>> return NotFound(self.avatar), ''
>> return rend.Page.locateChild(self, ctx, segments) # <===
> This code is wrong in 2 ways:
> 1) locateChild can return deferreds, you are not covering this aspect.
> 2) Why calling locateChild twice when once is enough? if the page is not
> rend.NotFound then it's the page you want... just return it.
Yes, I have marked the code with an arrow!
It was the first thing I notice when I have read the code.
>> By the way, is this code the best way to handle a login failure?
> Can't spot anything terribly wrong there.
>> Moreover, I still do not understand why, when replacing macro with
>> render, locateChild is called 3 times, instead of 2.
> You probably have other confusions in your source. As I said there's no
> link _at all_ between rendering and child locating.
Now the code is all ok.
Regards Manlio Perillo
More information about the Twisted-web