Issue Details (XML | Word | Printable)

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

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

PythonHandlerModule directive is broken.

Created: 10/Apr/05 03:18 PM   Updated: 05/Mar/06 01:53 PM
Return to search
Component/s: core
Affects Version/s: 3.1.4
Fix Version/s: 3.2.7

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works silent.diff.txt 2005-08-09 09:00 PM Graham Dumpleton 1 kB

Resolution Date: 22/Oct/05 04:41 PM


 Description  « Hide
Documentation for PythonHandlerModule says:

  PythonHandlerModule can be used an alternative to Python*Handler directives.
  The module specified in this handler will be searched for existence of functions
  matching the default handler function names, and if a function is found, it will
  be executed.

The suggestion is that it will not complain if a particular handler is defined, ie.,
only executes the ones it finds and doesn't worry about the rest. The example
even supports this by saying that:

  For example, instead of:

    PythonAutenHandler mymodule
    PythonHandler mymodule
    PythonLogHandler mymodule

  one can simply say

    PythonHandlerModule mymodule

BTW, "PythonAutenHandler" is spelt wrong in documentation, not by me.

The "mod_python.c" code also seems be coded so that if a handler is defined
in the module that it will not complain.

    python_directive_handler(cmd, mconfig, "PythonPostReadRequestHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonTransHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonHeaderParserHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonAccessHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonAuthzHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonTypeHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonInitHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonLogHandler", val, SILENT);
    python_directive_handler(cmd, mconfig, "PythonCleanupHandler", val, SILENT);
    python_directive_handler(cmd, srv_conf, "PythonConnectionHandler", val, SILENT);

Ie., it has "SILENT" option and not "NOTSILENT" as is case when single handler is
specified.

Problem is that using "PythonHandlerModule" it gives back 500 error and if
"PythonDebug" is on you will see in the browser:

  Mod_python error: "PythonHeaderParserHandler mptest"

  Traceback (most recent call last):

    File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 291, in HandlerDispatch
      arg=req, silent=hlist.silent)

    File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 519, in resolve_object
      raise AttributeError, s

  AttributeError: module '/home/grahamd/public_html/phases/mptest.py' contains no 'headerparserhandler'

The passing of "SILENT" thus seems to not work.

The definitions of SILENT and NOTSILENT are:

  #define SILENT 0
  #define NOTSILENT 1

This eventually gets set as hlist.silent and gets passed as "silent" argument of
the "resolve_object()" method.

In the resolve_object() call of apache.py where this is checked, it is checked as:

        # don't throw attribute errors when silent
        if silent and not hasattr(obj, obj_str):
            return None

        # this adds a little clarity if we have an attriute error
        if obj == module and not hasattr(module, obj_str):
            if hasattr(module, "__file__"):
                s = "module '%s' contains no '%s'" % (module.__file__, obj_str)
                raise AttributeError, s

Is the logic the wrong way around here or am I just going nuts?

The result of "resolve_object()" is used as:

                if object:
                    ...

                elif hlist.silent:
                    result = DECLINED

This is supposed to propogate ignoring of the fact that the handler is missing,
but again logic is wrong way.

The simple solution may be:

  #define NOTSILENT 0
  #define SILENT 1

All uses of this silent flag needs to be reviewed though to determine if this is
going to stuff up other areas of the code.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #231034 Tue Aug 09 13:43:37 UTC 2005 jgallacher Fixed spelling error "PythonAutenHandler" as reported by Graham Dumpleton.
Ref MODPYTHON-46.
Files Changed
MODIFY /httpd/mod_python/trunk/Doc/modpython5.tex

Repository Revision Date User Message
ASF #231054 Tue Aug 09 15:37:04 UTC 2005 jgallacher Applied Graham's silent.diff.txt patch to correct SILENT/NOTSILENT
logic reversal in directive_PythonHandlerModule(). Patch also
disables adding "PythonConnectionHandler" in same function.
Ref MODPYTHON-46
Files Changed
MODIFY /httpd/mod_python/trunk/src/include/mod_python.h
MODIFY /httpd/mod_python/trunk/src/mod_python.c