durusmail: quixote-users: Non-reproducible problem: get_request() returns None
Non-reproducible problem: get_request() returns None
Non-reproducible problem: get_request() returns None
Daniele Varrazzo
2005-01-24
Hi Titus,

> ->   File
> ->
> "C:/Programmi/PiroSoftware/renapp\renapp\web\styles\renault\WebPage.ptl",
> -> line 28, in render_header
> ->     user = get_user()
> ->   File
> "c:\programmi\python23\Lib\site-packages\quixote\publish.py", line
> -> 885, in get_user
> ->     session = _publisher.get_request().session
> -> AttributeError: 'NoneType' object has no attribute 'session'

> this looks familiar to me!  What session handling mechanism are you
> using, and are you sure that sessions are being committed to a
> centrally accessible table?
>
> If I remember correctly, this error can be thrown by session handling
> code that is assigning a new session in the middle of the site, where
> your code expects a user to already be assigned.  The new session
> doesn't have a user attached to it yet, so your code breaks.

They should: the site load is low enough to allow me to use a file based
session storing mechanism without worring about the performance issues. I
use a slightly modified version of the
http://mail.mems-exchange.org/pipermail/quixote-users/2003-August/001908.html
recipe. I don't think it's a session-related issue: it's
_publisher.get_request() that is returning None.

> The sporadic nature of the error is almost certainly caused by the
> session table not being replicated/accessible across the different
> Apache processes.  Most of the time (on low load sites or while testing)
> process 0 will be handling requests; then, occasionally, after a quick
> redirect or multiple hits, process 1 will get a request & bomb because
> it doesn't have the right sessions in its session table.
I, too, believe the behaviour is related to the short delay between the
request issuing the redirect and the consequent request.

My handler.py is:

def handler(req):
    opts = req.get_options()

    package = opts.get('quixote-root-namespace')

    if package:
        pub = name2publisher.get(package)
        if pub is None:
            # initialization code here, run once in the app's lifetime
            ...

        return pub.publish_modpython(req)

    # No package provided
    return apache.HTTP_INTERNAL_SERVER_ERROR

class ModPythonPublisher(SessionPublisher):

    def __init__(self, package, session_mgr, config=None):
        SessionPublisher.__init__(self, root_namespace=package,
session_mgr=session_mgr, config=config)

    def publish_modpython(self, req):
        """publish_modpython() -> None

        Entry point from mod_python.
        """
        self.publish(apache.CGIStdin(req),
                     apache.CGIStdout(req),
                     sys.stderr,
                     apache.build_cgi_env(req))
        return apache.OK

    def process_request (self, request, env):
        """process_request(request : HTTPRequest, env : dict) : string

        Process a single request, given an HTTPRequest object.  The
        try_publish() method will be called to do the work and
        exceptions will be handled here.
        """
        self._set_request(request)
        try:
            self.parse_request(request)
            output = self.try_publish(request, env.get('PATH_INFO', ''))
        except ...
            # various exception handlers
        output = self.filter_output(request, output)
        self.log_request(request)
        return output

Because try_publish() gets called, i believe _set_request in
ModPythonPublisher.process_request() receives a None as a request. It is
conversly called by Publisher().publish, which creates the request given a
stdin being apache.CGIStdin(req) and an env being
apache.build_cgi_env(req). But it looks to me there is no way for
Publisher.create_request to return a None.

Thank you,

Daniele



reply