allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [27/50] git commit: [#4713] Use newer DuplicateKeyError and prevent potential infinite loop
Date Wed, 19 Sep 2012 18:43:27 GMT
[#4713] Use newer DuplicateKeyError and prevent potential infinite loop

Signed-off-by: Cory Johns <johnsca@geek.net>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/4b639d8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/4b639d8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/4b639d8f

Branch: refs/heads/master
Commit: 4b639d8f17134e5f8050f75568d9f385e1427d66
Parents: 2b5c68c
Author: Cory Johns <johnsca@geek.net>
Authored: Wed Sep 12 18:51:55 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Thu Sep 13 18:09:57 2012 +0000

----------------------------------------------------------------------
 Allura/allura/model/discuss.py |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4b639d8f/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index 8101495..a250718 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -2,7 +2,7 @@ import logging
 from datetime import datetime
 
 import pymongo
-from pymongo.errors import OperationFailure
+from pymongo.errors import DuplicateKeyError
 from pylons import c, g
 
 from ming import schema
@@ -152,16 +152,16 @@ class Thread(Artifact, ActivityObject):
     @classmethod
     def new(cls, **props):
         '''Creates a new Thread instance, ensuring a unique _id.'''
-        while True:
+        for i in range(5):
             try:
                 thread = cls(**props)
                 session(thread).flush(thread)
                 return thread
-            except OperationFailure as err:
-                if 'duplicate' in err.args[0]:
-                    session(thread).expunge(thread)
-                    continue
-                raise
+            except DuplicateKeyError as err:
+                if i == 4:
+                    raise
+                session(thread).expunge(thread)
+                continue
 
     @classmethod
     def discussion_class(cls):


Mime
View raw message