From 07f0cdadcdb780981bb0b8e2f46150374047adae Mon Sep 17 00:00:00 2001 From: Massimo Date: Thu, 14 Nov 2013 13:29:46 -0600 Subject: [PATCH] memdb conflict check, thanks Luca --- VERSION | 2 +- gluon/contrib/memdb.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index 254ca105..f2cb0069 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.7.4-stable+timestamp.2013.11.13.14.06.31 +Version 2.7.4-stable+timestamp.2013.11.14.13.28.53 diff --git a/gluon/contrib/memdb.py b/gluon/contrib/memdb.py index 8f181a64..e043da73 100644 --- a/gluon/contrib/memdb.py +++ b/gluon/contrib/memdb.py @@ -253,12 +253,15 @@ class Table(DALStorage): self._db(self.id > 0).delete() - def insert(self, **fields): - id = self._create_id() - if self.update(id, **fields): - return long(id) + + def insert(self, **fields): + # Checks 3 times that the id is new. 3 times is enough! + for i in range(3): + id = self._create_id() + if self.get(id) is None and self.update(id, **fields): + return long(id) else: - return None + raise RuntimeError("Too many ID conflicts") def get(self, id): val = self._tableobj.get(self._id_to_key(id))