Uploaded image for project: 'mod_python'
  1. mod_python
  2. MODPYTHON-100

raise apache.SERVER_RETURN, apache.OK aborts handlers.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.4, 3.2.7
    • Fix Version/s: 3.3.1
    • Component/s: core
    • Labels:
      None

      Description

      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")

      1. 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.

        Activity

        Hide
        grahamd Graham Dumpleton added a comment -

        Linked issues which will be addressed by rewritten module importer and top level handler dispatcher.

        Show
        grahamd Graham Dumpleton added a comment - Linked issues which will be addressed by rewritten module importer and top level handler dispatcher.
        Hide
        grahamd Graham Dumpleton added a comment -

        Fix back ported into existing importer from new importer. Thus no longer dependent on new importer being used.

        Show
        grahamd Graham Dumpleton added a comment - Fix back ported into existing importer from new importer. Thus no longer dependent on new importer being used.

          People

          • Assignee:
            grahamd Graham Dumpleton
            Reporter:
            grahamd Graham Dumpleton
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development