From 95aef51ee5e70199f2ae085702b7d7d86aab43b9 Mon Sep 17 00:00:00 2001 From: bch <> Date: Wed, 9 May 2007 10:37:59 +0000 Subject: [PATCH] Bugfix Concunrrency write : increased the db precision for the write date + update read_time value very shortly after the write on the server side. This ovoid some problem when somebody clic on save button very nervously bzr revid: bch-31a0315e15c40fed080843b1f5f0d9499eda0b04 --- bin/netsvc.py | 2 +- bin/osv/orm.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bin/netsvc.py b/bin/netsvc.py index f563c4bf001..03a931c3b92 100644 --- a/bin/netsvc.py +++ b/bin/netsvc.py @@ -198,7 +198,7 @@ class GenericXMLRPCRequestHandler: import traceback try: n=self.path.split("/")[-1] - print "TERP-CALLING:",n,method,params +# print "TERP-CALLING:",n,method,params s=LocalService(n) m=getattr(s,method) s._service._response=None diff --git a/bin/osv/orm.py b/bin/osv/orm.py index e87fd4d0658..695d2284cd1 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -850,9 +850,10 @@ class orm(object): def write(self, cr, user, ids, vals, context={}): delta= context.get('read_delta',False) if delta and self._log_access: - cr.execute("select (now() - '%s'::interval - min(write_date)) >= '0'::interval from %s where id in (%s)"% (delta,self._table,",".join(map(str, ids))) ) - res= cr.fetchall() - if res and (res.pop()[0] == 0): + cr.execute("select (now() - '%s'::interval - min(write_date)) > '0'::interval from %s where id in (%s)"% (delta,self._table,",".join(map(str, ids))) ) + res= cr.fetchone() + if res and (not res[0]): + print res raise except_orm('ConcurrencyException', 'This record was modified in the meanwhile') self.pool.get('ir.model.access').check(cr, user, self._name, 'write') @@ -880,7 +881,7 @@ class orm(object): updend.append(field) if self._log_access: upd0.append('write_uid=%d') - upd0.append('write_date=current_timestamp(0)') + upd0.append('write_date=now()') upd1.append(user) if len(upd0): @@ -910,6 +911,9 @@ class orm(object): self._validate(cr, user, ids) + if context.has_key('read_delta'): + del context['read_delta'] + wf_service = netsvc.LocalService("workflow") for id in ids: wf_service.trg_write(user, self._name, id, cr) @@ -977,7 +981,7 @@ class orm(object): upd_todo.append(field) if self._log_access: upd0 += ',create_uid,create_date' - upd1 += ',%d,current_timestamp(0)' + upd1 += ',%d,now()' upd2.append(user) cr.execute('insert into '+self._table+' (id,perm_id'+upd0+") values ("+str(id_new)+',NULL'+upd1+')', tuple(upd2)) upd_todo.sort(lambda x,y: self._columns[x].priority-self._columns[y].priority)