[IMP] res_users.login(): eliminate a possibility to get a transaction rollbacked
authorVo Minh Thu <vmt@openerp.com>
Thu, 12 Jan 2012 08:40:30 +0000 (09:40 +0100)
committerVo Minh Thu <vmt@openerp.com>
Thu, 12 Jan 2012 08:40:30 +0000 (09:40 +0100)
because of concurrent access. This can happen when the same user is trying to log in
from many clients concurrently.

bzr revid: vmt@openerp.com-20120112084030-kkz1aztp5t6vkbh9

gunicorn.conf.py
openerp/addons/base/res/res_users.py

index 9962493..aaf48c7 100644 (file)
@@ -35,7 +35,7 @@ conf = openerp.tools.config
 
 # Path to the OpenERP Addons repository (comma-separated for
 # multiple locations)
-conf['addons_path'] = '/home/openerp/addons/trunk,/home/openerp/web/trunk/addons'
+conf['addons_path'] = '/home/thu/repos/addons/trunk-import-hook,/home/thu/repos/web/trunk-import-hook/addons'
 
 # Optional database config if not using local socket
 #conf['db_name'] = 'mycompany'
index 67b9c01..8962f6d 100644 (file)
@@ -471,12 +471,17 @@ class users(osv.osv):
             return False
         cr = pooler.get_db(db).cursor()
         try:
+            # We autocommit: our single request will be performed atomically.
+            # (In this way, there is no opportunity to have two transactions
+            # interleaving ther cr.execute()..cr.commit() calls and have one
+            # of them rollbacked due to a concurrent access.)
+            # We effectively unconditionally write the res_users line.
+            cr.autocommit(True)
             cr.execute("""UPDATE res_users
                             SET date = now() AT TIME ZONE 'UTC'
                             WHERE login=%s AND password=%s AND active RETURNING id""",
                        (tools.ustr(login), tools.ustr(password)))
             res = cr.fetchone()
-            cr.commit()
             if res:
                 return res[0]
             else: