diff --git a/pymongo/errors.py b/pymongo/errors.py index ba6fec5876..fd55226ab3 100644 --- a/pymongo/errors.py +++ b/pymongo/errors.py @@ -240,8 +240,9 @@ class BulkWriteError(OperationFailure): def __init__(self, results): super(BulkWriteError, self).__init__( "batch op errors occurred", 65, results) - # For pickle support - self.args = (results,) + + def __reduce__(self): + return self.__class__, (self.details,) class InvalidOperation(PyMongoError): diff --git a/test/test_errors.py b/test/test_errors.py index 5829d01de5..968c8ebd74 100644 --- a/test/test_errors.py +++ b/test/test_errors.py @@ -93,6 +93,7 @@ def test_pickle_OperationFailure(self): def test_pickle_BulkWriteError(self): exc = BulkWriteError({}) self.assertOperationFailureEqual(exc, pickle.loads(pickle.dumps(exc))) + self.assertIn("batch op errors occurred", str(exc)) def test_pickle_EncryptionError(self): cause = OperationFailure('error', code=5, details={},