
tseaver at zope
Oct 6, 2004, 7:11 PM
Post #21 of 32
(3617 views)
Permalink
|
Richard Jones wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Thu, 7 Oct 2004 11:19 am, Donovan Baarda wrote: > >>On Thu, 2004-10-07 at 11:13, Sidnei da Silva wrote: >> >>>On Thu, Oct 07, 2004 at 11:10:05AM +1000, Donovan Baarda wrote: >>>Returning None gives a 'object cannot be published because doesn't >>>have a docstring.' which is even worse. >> >>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? >> >>Perhaps AttributeError = 404 is a good idea after all... > > > No, as already mentioned, this will mask any application bugs that raise > AttributeError. > > NotFound exists for this purpose, doesn't it? NotFound is an HTTP Protocol level mapping for an error; it should *not* be raised by application code. In particular, __bobo_traverse__ is called *both* by the publisher *and* by unrestrictedTraverse; raising NotFound is *totally* unexpected and inappropriate for the second case. The current schizophrenia among its callers makes writing a sane __bobo_traverse__ implementation logically impossible. BTW, note that the publisher *already* DWIMs AttributeError and KeyError into NotFound for traversals which do not have a __bobo_traverse__; the proposed change just makes the DWIM more regular, and thus more predictable. The alternatives are: - As Sidnei proposed, have the publisher map {Attribute,Key}Errors raised by __bobo_traverse__ onto NotFound, except when running in debug mode. Don't modify unrestrictedTraverse at all. - Define a special error, e.g. OFS.Traversable.Nonesuch, and make raising it part of the contract for __bobo_traverse__; raising {Attribute,Key,Index,Value}Error from __bobo_traverse__ would then be an unambiguous application error. We should still decide what to do about such errors, and should probably remove the publisher's current DWIM (when it calls getattr / getitem directly). The downside here is having to modify the dozen or so __bobo_traverse__ implementations in the core, plus breaking uncountable third-party implementations, for the sake of API purity. - Morph NotFound into a more generic exception, and make it part of the contract (note that this is essentially identical to the previous alternative, except for spelling). - Make returning 'None' for "not found" the contract for __bobo_traverse__, and modify both the publisher and unrestrictedTraverse to look for it. Again, we would need to revisit the core implementations, and risk breaking third-party versions. - Define something like Zope3's exception views, and remove all the hardwired exception DWIM from the publisher (not feasible, but one of the logical alternatives). - Continue to have the current set of inconsistent mappings of {Attribute,Key}Error to NotFound in some cases, but propagated as ServerError in others (note that the DWIM in question is already suppressed when running in debug mode, where losing the original exception's information might actually be a problem). Tres. -- =============================================================== Tres Seaver tseaver [at] zope Zope Corporation "Zope Dealers" http://www.zope.com _______________________________________________ Zope-Coders mailing list Zope-Coders [at] zope http://mail.zope.org/mailman/listinfo/zope-coders
|