On Fri, 2008-11-14 at 00:39 -0800, ershadul wrote:
> Dear Steve Holden,
> Please consider the following block i wrote:
> 
> def process_request(self, request):
>         request.db_session = session()
>         request.db_session.time_stamp = str(datetime.datetime.now())
>         print 'process_request', request.db_session.time_stamp
> 
>     def process_response(self, request, response):
>         try:
>             print 'process_response', request.db_session.time_stamp
>             session_destroy(request.db_session)
>         except AttributeError:
>             print 'process_response: db_session not found'
>             #pass
>         return response
> 
> .... For some links i got the message 'db_session not found' , not for
> all request.
> that is for some requests process_response is called at first.
> Look at the output at console:
> These are OK.
> Django version 1.0-alpha-SVN-unknown, using settings
> 'divineba.settings'
> Development server is running at http://127.0.0.1:8000/
> Quit the server with CTRL-BREAK.
> process_request 2008-11-14 14:33:07.437000
> process_response 2008-11-14 14:33:07.437000
> [14/Nov/2008 14:33:07] "GET /journal/view HTTP/1.1" 200 22616
> process_request 2008-11-14 14:33:07.734000
> process_response 2008-11-14 14:33:07.734000
> [14/Nov/2008 14:33:07] "GET /js/jquery.js HTTP/1.1" 304 0
> process_request 2008-11-14 14:33:07.781000
> process_response 2008-11-14 14:33:07.781000
> [14/Nov/2008 14:33:07] "GET /js/jquery.autocomplete.js HTTP/1.1" 304 0
> 
> But for some links we got the following output:
> 
> Django version 1.0-alpha-SVN-unknown, using settings
> 'divineba.settings'
> Development server is running at http://127.0.0.1:8000/
> Quit the server with CTRL-BREAK.
> process_response process_response: db_session not found
> [14/Nov/2008 14:36:14] "GET /account/chart HTTP/1.1" 301 0
> process_request 2008-11-14 14:36:14.531000
> process_response 2008-11-14 14:36:14.531000
> [14/Nov/2008 14:36:14] "GET /account/chart/ HTTP/1.1" 200 6717
> 
> Look at the 4th line:
>  "process_response process_response: db_session not found"
> 
> Why for some links process_response is called before process_request?
> Logically each process_request is called before process_response.
> Can you provide any suggestion please ?

There's no guarantee that the request method is going to be called. If
another middleware earlier in the stack returned a response, the
remainder of the middleware stack (including your process_request()
method) is skipped -- in the request processing path.

However, at that point, the full response processing path, including all
middleware functions, is executed. So if something, say, the cache
middleware intercepted the request before it got to your middleware,
your request handler won't be run. But your response handler will be.
You need to be able to handle that situation (your response handler
needs to check that something like db_session exists before accessing
it).

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to