Skip to content

Commit c800cd1

Browse files
committed
PYTHON-837 - Implement CRUD spec exception hierarchy.
1 parent b559ab0 commit c800cd1

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

doc/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ now accepts an `address` parameter.
8787
:mod:`~pymongo.errors` Changes
8888
..............................
8989

90-
The exception class ``UnsupportedOption`` is deleted.
90+
The exception classes ``UnsupportedOption`` and ``TimeoutError`` are deleted.
9191

9292
:mod:`~gridfs` Changes
9393
......................

pymongo/errors.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,21 @@ class ExecutionTimeout(OperationFailure):
126126
"""
127127

128128

129-
class TimeoutError(OperationFailure):
130-
"""DEPRECATED - will be removed in PyMongo 3.0. See WTimeoutError instead.
129+
class WriteConcernError(OperationFailure):
130+
"""Base exception type for errors raised due to write concern.
131+
132+
.. versionadded:: 3.0
133+
"""
134+
135+
136+
class WriteError(OperationFailure):
137+
"""Base exception type for errors raised during write operations.
138+
139+
.. versionadded:: 3.0
131140
"""
132141

133142

134-
class WTimeoutError(TimeoutError):
143+
class WTimeoutError(WriteConcernError):
135144
"""Raised when a database operation times out (i.e. wtimeout expires)
136145
before replication completes.
137146
@@ -142,7 +151,7 @@ class WTimeoutError(TimeoutError):
142151
"""
143152

144153

145-
class DuplicateKeyError(OperationFailure):
154+
class DuplicateKeyError(WriteError):
146155
"""Raised when an insert or update fails due to a duplicate key error."""
147156

148157

pymongo/helpers.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
from bson.son import SON
2525
from pymongo.errors import (CursorNotFound,
2626
DuplicateKeyError,
27-
OperationFailure,
2827
ExecutionTimeout,
29-
WTimeoutError,
30-
NotMasterError)
28+
NotMasterError,
29+
OperationFailure,
30+
WriteError,
31+
WriteConcernError,
32+
WTimeoutError)
3133
from pymongo.message import query
3234

3335

@@ -244,13 +246,15 @@ def _check_write_command_response(results):
244246
error["index"] += offset
245247
if error.get("code") == 11000:
246248
raise DuplicateKeyError(error.get("errmsg"), 11000, error)
249+
raise WriteError(error.get("errmsg"), error.get("code"), error)
247250
else:
248251
error = result["writeConcernError"]
249252
if "errInfo" in error and error["errInfo"].get('wtimeout'):
250253
# Make sure we raise WTimeoutError
251-
raise WTimeoutError(error.get("errmsg"),
252-
error.get("code"), error)
253-
raise OperationFailure(error.get("errmsg"), error.get("code"), error)
254+
raise WTimeoutError(
255+
error.get("errmsg"), error.get("code"), error)
256+
raise WriteConcernError(
257+
error.get("errmsg"), error.get("code"), error)
254258

255259

256260
def _fields_list_to_dict(fields, option_name):

0 commit comments

Comments
 (0)