From 9e6378a06bdefaabfccb64b6eb46727213d374bf Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 21 Jan 2009 18:37:28 +0100 Subject: [PATCH] [FIX] concurrency check: handle the case of the O2M fields bzr revid: christophe@tinyerp.com-20090121173728-pk4dkpqj79bjyntg --- bin/osv/orm.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index ea447fad6e9..1a5d67456af 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -2039,20 +2039,19 @@ class orm(orm_template): if not context: return if context.get(self.CONCURRENCY_CHECK_FIELD) and self._log_access: + def key(oid): + return "%s,%s" % (self._name, oid) santa = "(id = %s AND %s < COALESCE(write_date, create_date, now())::timestamp)" for i in range(0, len(ids), cr.IN_MAX): - sub_ids = tools.flatten(((i, context[self.CONCURRENCY_CHECK_FIELD][str(i)]) - for i in ids[i:i+cr.IN_MAX] - if str(i) in context[self.CONCURRENCY_CHECK_FIELD])) + sub_ids = tools.flatten(((oid, context[self.CONCURRENCY_CHECK_FIELD][key(oid)]) + for oid in ids[i:i+cr.IN_MAX] + if key(oid) in context[self.CONCURRENCY_CHECK_FIELD])) if sub_ids: cr.execute("SELECT count(1) FROM %s WHERE %s" % (self._table, " OR ".join([santa]*(len(sub_ids)/2))), sub_ids) res = cr.fetchone() if res and res[0]: raise except_orm('ConcurrencyException', _('Records were modified in the meanwhile')) - del context[self.CONCURRENCY_CHECK_FIELD] - - def unlink(self, cr, uid, ids, context=None): if not ids: return True