Issue Details (XML | Word | Printable)

Key: MODPYTHON-100
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Graham Dumpleton
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

raise apache.SERVER_RETURN, apache.OK aborts handlers.

Created: 18/Dec/05 02:47 PM   Updated: 02/Apr/07 11:46 AM
Return to search
Component/s: core
Affects Version/s: 3.1.4, 3.2.7
Fix Version/s: 3.3.1

Time Tracking:
Not Specified

Resolution Date: 03/May/06 05:51 PM


 Description  « Hide
If multiple handlers are defined for a phase and a handler which isn't the last one, rather than returning the value apache.OK as the result, raises the apache.SERVER_RETURN exception with apache.OK as argument, then processing of subsequent handlers in that phase are being aborted.

Ie., consider the example with .htaccess file of:

  SetHandler mod_python
  PythonHandler example::handler_1
  PythonHandler example::handler_2

and example.py of:

  from mod_python import apache

  def handler_1(req):
    apache.log_error("handler_1")
    req.content_type = 'text/plain'
    req.write("HELLO")
    # return apache.OK
    raise apache.SERVER_RETURN, apache.OK

  def handler_2(req):
    apache.log_error("handler_2")
    return apache.OK

The expectation would be that returning the value apache.OK from the handler function and raising an exception of type apache.SERVER_RETURN with argument apache.OK would be equivalent, but they aren't. When the exception is being raised, handler_2() function is never executed.

It would seem more sensible that they are equivalent as there are other specific status values that can be used in the case that one wants to prevent further handlers in the phase from being executed. For example, as appropriate, one of:

  req.status = apache.HTTP_OK
  raise apache.SERVER_RETURN, apache.DONE

or:

  raise apache.SERVER_RETURN, (apache.DONE,apache.HTTP_OK)

or:

  raise apache.SERVER_RETURN, apache.DECLINED

To fix this, the apache.SERVER_RETURN exception should be processed within the processing loop for each handler, rather than being handled outside of the loop. The status as returned by the exception should be translated to look like it was returned by the handler and dealt with as for other status values returned explicitly.

No patch, perhaps wait for my rewrite of the importer for mod_python 3.3 as already addresses this issue. :-)



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Graham Dumpleton made changes - 10/Mar/06 01:40 PM
Field Original Value New Value
Link This issue depends upon MODPYTHON-143 [ MODPYTHON-143 ]
Graham Dumpleton added a comment - 10/Mar/06 01:40 PM
Linked issues which will be addressed by rewritten module importer and top level handler dispatcher.

Graham Dumpleton made changes - 01/Apr/06 01:37 PM
Assignee Graham Dumpleton [ grahamd ]
Graham Dumpleton made changes - 01/Apr/06 01:56 PM
Status Open [ 1 ] In Progress [ 3 ]
Repository Revision Date User Message
ASF #399248 Wed May 03 10:49:48 UTC 2006 grahamd When using stacked handlers and a SERVER_RETURN exception was used to
return an OK status for that handler, any following handlers weren't being
run if appropriate for the phase. (MODPYTHON-100)

The change was backported from new module importer which already included
the fix, to existing importer.
Files Changed
MODIFY /httpd/mod_python/trunk/test/htdocs/tests.py
MODIFY /httpd/mod_python/trunk/test/test.py
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/__init__.py
MODIFY /httpd/mod_python/trunk/Doc/appendixc.tex
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/apache.py
MODIFY /httpd/mod_python/trunk/src/include/mpversion.h

Graham Dumpleton made changes - 03/May/06 05:41 PM
Link This issue depends upon MODPYTHON-143 [ MODPYTHON-143 ]
Graham Dumpleton added a comment - 03/May/06 05:51 PM
Fix back ported into existing importer from new importer. Thus no longer dependent on new importer being used.

Graham Dumpleton made changes - 03/May/06 05:51 PM
Resolution Fixed [ 1 ]
Fix Version/s 3.3 [ 12310101 ]
Status In Progress [ 3 ] Resolved [ 5 ]
Graham Dumpleton made changes - 02/Apr/07 11:46 AM
Status Resolved [ 5 ] Closed [ 6 ]