[Zope-Coders] Changes to ZPublisher

Chris McDonough chrism at plope.com
Wed Oct 6 13:30:40 EDT 2004


On Wed, 2004-10-06 at 13:06, Sidnei da Silva wrote:
> On Wed, Oct 06, 2004 at 12:54:14PM -0400, Chris McDonough wrote:
> | > I suppose you are referring to the stuff below here.
> | 
> | It appears I misread this; you don't do getattr or getitem when you get
> | an AttributeError/KeyError from __bt__, that's good.
> 
> I actually do right now, but I feel it's wrong. ZPublisher didn't do
> it before. If you say not doing it is good, then I'm surely removing
> it.
> 
> | > The intention here is not introduce anything new, but to traversal
> | > using __bobo_traverse__ behave the same way as attribute traversal
> | > with regards to exceptions raised.
> | 
> | I guess the difference is that the publisher is trying to catch
> | AttreibuteError/KeyError/TypeError/IndexError as a result of its own
> | operations to *get* the object.  I don't think it was ever intended that
> | if you raise an AttributeError/KeyError from app code (implemented, in
> | this case, in __bt__) that it would have the side effect of causing a
> | NotFoundError.  I know that's the effect of the current code, but I
> | really don't think that when the Publisher was implemented that this was
> | ever considered.
> 
> The main reasoning for all of this was that:
> 
> - __bt__ exceptions would pass by unmodified on ZPublisher
> - so we thought raising NotFound from __bt__ would be fine
> - but then it broke PageTemplates.Expressions (SubPathExpression)
>   because it doesn't expect a NotFound

Yup got it so far.

> - raising AttributeError copes well with PageTemplates.Expressions
> - but in the case of ZPublisher it should really be NotFound, as it is
>   really coming from the browser, and not trying to find an attribute
>   in application code

But isn't __bt__ "application code"?  Maybe not.  Maybe that's what I'm
stuck on.

IMO, we should really have a sentinel exception to indicate something
that should be raised up to the publisher and which should cause a not
found error (something with the same "punch up through the stack"
semantics as ConflictError, IOW).  But I realize we don't have that now
for __getitem__/__getattr__ and things still appear to work ok, so maybe
I'm just being dogmatic about it.

> - Tres said that NotFound should not be raised by application code,
>   but only by ZPublisher.

Agreed.  Although, maybe in the case of __bt__, you could bend this
rule?  I really don't know what the right answer is.

> So, just to clarify, are you ok with converting the
> AttributeError/KeyError to NotFound on ZPublisher and not trying to
> fallback to __getattr__/__getitem__?

I guess I'd be -0 on it given this explanation of the problem you're
trying to solve.

- C




More information about the Zope-Coders mailing list