PYTHON-837 - Implement CRUD spec exception hierarchy.
This commit is contained in:
parent
b559ab0b46
commit
c800cd18ad
@ -87,7 +87,7 @@ now accepts an `address` parameter.
|
||||
:mod:`~pymongo.errors` Changes
|
||||
..............................
|
||||
|
||||
The exception class ``UnsupportedOption`` is deleted.
|
||||
The exception classes ``UnsupportedOption`` and ``TimeoutError`` are deleted.
|
||||
|
||||
:mod:`~gridfs` Changes
|
||||
......................
|
||||
|
||||
@ -126,12 +126,21 @@ class ExecutionTimeout(OperationFailure):
|
||||
"""
|
||||
|
||||
|
||||
class TimeoutError(OperationFailure):
|
||||
"""DEPRECATED - will be removed in PyMongo 3.0. See WTimeoutError instead.
|
||||
class WriteConcernError(OperationFailure):
|
||||
"""Base exception type for errors raised due to write concern.
|
||||
|
||||
.. versionadded:: 3.0
|
||||
"""
|
||||
|
||||
|
||||
class WTimeoutError(TimeoutError):
|
||||
class WriteError(OperationFailure):
|
||||
"""Base exception type for errors raised during write operations.
|
||||
|
||||
.. versionadded:: 3.0
|
||||
"""
|
||||
|
||||
|
||||
class WTimeoutError(WriteConcernError):
|
||||
"""Raised when a database operation times out (i.e. wtimeout expires)
|
||||
before replication completes.
|
||||
|
||||
@ -142,7 +151,7 @@ class WTimeoutError(TimeoutError):
|
||||
"""
|
||||
|
||||
|
||||
class DuplicateKeyError(OperationFailure):
|
||||
class DuplicateKeyError(WriteError):
|
||||
"""Raised when an insert or update fails due to a duplicate key error."""
|
||||
|
||||
|
||||
|
||||
@ -24,10 +24,12 @@ from bson.py3compat import itervalues, string_type, iteritems
|
||||
from bson.son import SON
|
||||
from pymongo.errors import (CursorNotFound,
|
||||
DuplicateKeyError,
|
||||
OperationFailure,
|
||||
ExecutionTimeout,
|
||||
WTimeoutError,
|
||||
NotMasterError)
|
||||
NotMasterError,
|
||||
OperationFailure,
|
||||
WriteError,
|
||||
WriteConcernError,
|
||||
WTimeoutError)
|
||||
from pymongo.message import query
|
||||
|
||||
|
||||
@ -244,13 +246,15 @@ def _check_write_command_response(results):
|
||||
error["index"] += offset
|
||||
if error.get("code") == 11000:
|
||||
raise DuplicateKeyError(error.get("errmsg"), 11000, error)
|
||||
raise WriteError(error.get("errmsg"), error.get("code"), error)
|
||||
else:
|
||||
error = result["writeConcernError"]
|
||||
if "errInfo" in error and error["errInfo"].get('wtimeout'):
|
||||
# Make sure we raise WTimeoutError
|
||||
raise WTimeoutError(error.get("errmsg"),
|
||||
error.get("code"), error)
|
||||
raise OperationFailure(error.get("errmsg"), error.get("code"), error)
|
||||
raise WTimeoutError(
|
||||
error.get("errmsg"), error.get("code"), error)
|
||||
raise WriteConcernError(
|
||||
error.get("errmsg"), error.get("code"), error)
|
||||
|
||||
|
||||
def _fields_list_to_dict(fields, option_name):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user