[Zope-Coders] Re: Changes to ZPublisher

Tres Seaver tseaver at zope.com
Wed Oct 6 22:15:13 EDT 2004


Donovan Baarda wrote:
> On Thu, 2004-10-07 at 11:24, Sidnei da Silva wrote:
> 
>>| Hmm... didn't notice that... nasty.
>>| 
>>| So what is the current way for a __bobo_traverse__ to indicate "object
>>| does not exist" and result in a 404?
>>
>>There's no way :) You could raise NotFound yourself, but then it
>>breaks PageTemplates.
>>
>>| Perhaps AttributeError = 404 is a good idea after all...
>>
>>It's the best I could come up with.
> 
> 
> It seems there are several possible solutions to this;
> 
> 1) Fix PageTemplates so that NotFound doesn't break it (dunno what is
> involved).
> 
> 2) Fix returning None so that it returns 404 instead of "No Docstring",
> and introduce some exception for the "No Docstring" case.
> 
> 3) make AttributeError = 404, and document it like hell so people know
> to catch them and raise as some other Error if they don't want a 404.
> 
> To me 1) seems like a good idea regardless. For 2) I really don't
> understand why None results in "No Docstring"... is this really right?
> If NotFound worked, I'm not sure what returning None should mean, but
> "No Docstring" doesn't seem to be it. Option 3) seems unattractive to
> me.

The publisher's job has always been to mediate between what the protocl 
(HTTP) expects, and what the application delivers.  In this case, the 
difference is between having the HTTP response code be 404, or having it 
be 500.  Making either choice is DWIM ("do what I mean");  it happens to
be consistent with the other publisher code (immediately following the
test for __bobo_traverse__) to treat it as a 404 instead of a 500.

In debug mode, we should prefer a 500, because it preserves the original
exception information;  this is the current behavior for errors raised 
from getattr / getitem, and would be the behavior under Sidnei's 
proposed change.

Tres.
-- 
===============================================================
Tres Seaver                                tseaver at zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com



More information about the Zope-Coders mailing list