Skip to content

Commit a88a9be

Browse files
Merge pull request pandas-dev#31 from manahl/arctic_exception_hook
MDP-341 ensure the external error hook is called when an exception occurs
2 parents 006e251 + 6c847c6 commit a88a9be

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

arctic/decorators.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pymongo.errors import AutoReconnect, OperationFailure, DuplicateKeyError, ServerSelectionTimeoutError
99

10-
from .hooks import _log_exception_hook as _log_exception
10+
from .hooks import log_exception as _log_exception
1111

1212
logger = logging.getLogger(__name__)
1313

tests/unit/test_decorators_unit.py

+24
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from arctic import decorators
77
from arctic.decorators import mongo_retry, _get_host
88
from pymongo.collection import Collection
9+
from arctic.hooks import register_log_exception_hook
910

1011

1112
def test_mongo_retry():
@@ -35,6 +36,29 @@ def foo(self):
3536
assert he.call_args_list[1][0][2] == 2
3637

3738

39+
def test_mongo_retry_hook_changes():
40+
retries = [2]
41+
self = MagicMock()
42+
hook1 = Mock()
43+
register_log_exception_hook(hook1)
44+
hook2 = Mock()
45+
46+
@mongo_retry
47+
def foo(self):
48+
if retries[0] == 2:
49+
retries[0] -= 1
50+
raise OperationFailure('error')
51+
elif retries[0] == 1:
52+
register_log_exception_hook(hook2)
53+
retries[0] -= 1
54+
raise AutoReconnect('error')
55+
return "success"
56+
foo(self)
57+
58+
assert hook1.call_count == 1
59+
assert hook2.call_count == 1
60+
61+
3862
def test_mongo_retry_fails():
3963
error = OperationFailure('error')
4064
retries = [16]

0 commit comments

Comments
 (0)