I am using TG 2.0.4.  Till now I used to save the user_id in the __before__ 
method of a controller and use it later in an exposed method of the same 
controller.  During testing, I came across a scenario (race condition) 
where the self.user_id is not what I expected inside foo().  It seems that 
self.user_id is overwritten by request2 when I am processing request1 in 
parallel.  All along I thought that the values stored in the controller 
self variable are request specific.  I figure my understanding is wrong.   
Can someone confirm! 

If I want to store request specific information to be used later in the 
processing, should I store it in the *request *object itself?  Or maybe 
create a req_context object and store all the needed information, and add 
the req_context object to the request.

Any other suggestions welcome.


Thanks

   def __before__(self, *args, **kw):
        tmpl_context.menu_items = self.menu_items
        tmpl_context.title = title
        identity = request.environ.get('repoze.who.identity')
        self.user_id = identity['user'].user_id
        self.user_name = identity['user'].user_name

@expose()
def foo(self):
     # use self.user_id for some operation

http://turbogears.org/2.0/docs/modules/tgcontroller.html
__before__(**args*, ***kw*)Override this method to define any action you 
would like taken before the controller code is executed. This is 
particularly useful for defining a Controller-wide specification (all 
methods) for things like: setting up variables/objects in the template 
context, restricting access, or other tasks which should be executed before 
the controller method is called.

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/turbogears/-/5M8HCqCL0cEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to