[Zope-dev] response.status is not set properly when Zope2 publication failure events are notified

Godefroid Chapelle gotcha at bubblenet.be
Mon Sep 12 07:27:04 EST 2011


Hi,

Short story :

response.status is not set when PubBeforeAbort and PubFailure events are 
notified.

Any code in the event handlers trying to use response.status always gets 
200 even though an exception has happened.

Longer story :

publish function in ZPublisher.Publish.py is notifiying all publication 
events ZPublisher.interfaces.IPubEvent.

It is called by publish_module_standard function which is in charge of 
transforming exceptions into HTTP status by calling response.exception().

However, this happens after the publishing events have been notified.

IOW, when failure events (PubBeforeAbort and PubFailure) are notified, 
request.status is still 200 :-(

Proposal attempt:

First, a disclaimer : there are so many nested try except, try finally 
in publish and publish_module_standard functions that I am sure I do not 
fully understand the code. However, I'll state my thoughts as a starting 
point.

I have the feeling that moving the call to response.exception() into the 
publish function before the events are notified would break a lot of 
code. Maybe we could just move the setStatus() call made in 
response.exception().

We might move the notification of PubFailure to response.exception(). 
However, its semantics would then change slightly and it is not obvious 
which exc_info would then be passed to the event.

I'd appreciate feedback on this issue.
-- 
Godefroid Chapelle (aka __gotcha) http://bubblenet.be


More information about the Zope-Dev mailing list