You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/09/19 20:43:27 UTC
[27/50] git commit: [#4713] Use newer DuplicateKeyError and prevent
potential infinite loop
[#4713] Use newer DuplicateKeyError and prevent potential infinite loop
Signed-off-by: Cory Johns <jo...@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 <jo...@geek.net>
Authored: Wed Sep 12 18:51:55 2012 +0000
Committer: Dave Brondsema <db...@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):