From 86d58113e52c8331ef83fd5849019c5422d7e62b Mon Sep 17 00:00:00 2001 From: Pascal Corpet Date: Mon, 23 Nov 2020 18:46:33 +0100 Subject: [PATCH] PYTHON-2438 Fix str representation of BulkWriteError (#522) --- pymongo/errors.py | 5 +++-- test/test_errors.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pymongo/errors.py b/pymongo/errors.py index ba6fec587..fd55226ab 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 5829d01de..968c8ebd7 100644 --- a/test/test_errors.py +++ b/test/test_errors.py @@ -93,6 +93,7 @@ class TestErrors(PyMongoTestCase): 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={},