Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-2415

Can't pickle BulkWriteError

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker - P1
    • Resolution: Fixed
    • Affects Version/s: 3.11
    • Fix Version/s: 3.11.1
    • Component/s: Error Handling
    • Labels:
    • Environment:
      CPython 3.8.5

      Description

      import pickle
      import pymongo
       
      db = pymongo.MongoClient().demo
      db.drop_collection("demo")
      db.create_collection("demo", validator={"$jsonSchema": {"required": ["foo"]}})
       
      try:
          db.demo.insert_many([{"bar": 1}])
      except Exception as e:
          exc = e
      exc
      

      pymongo.errors.BulkWriteError("batch op errors occurred, full error: {'writeErrors': [{'index': 0, 'code': 121, 'errmsg': 'Document failed validation', 'op': {'bar': 1, '_id': ObjectId('5fa2c64c60c6844f5fef6964')}}], 'writeConcernErrors': [], 'nInserted': 0, 'nUpserted': 0, 'nMatched': 0, 'nModified': 0, 'nRemoved': 0, 'upserted': []}")
      

      pickle.loads(pickle.dumps(exc))
      

      ---------------------------------------------------------------------------
      AttributeError                            Traceback (most recent call last)
      <ipython-input-27-3ba4d0d7966c> in <module>
      ----> 1 pickle.loads(pickle.dumps(exc))
       
      ~/miniconda3/envs/demo/lib/python3.8/site-packages/tblib/pickling_support.py in unpickle_exception(func, args, cause, tb)
           24 
           25 def unpickle_exception(func, args, cause, tb):
      ---> 26     inst = func(*args)
           27     inst.__cause__ = cause
           28     inst.__traceback__ = tb
       
      ~/miniconda3/envs/demo/lib/python3.8/site-packages/pymongo/errors.py in __init__(self, results)
          239     """
          240     def __init__(self, results):
      --> 241         super(BulkWriteError, self).__init__(
          242             "batch op errors occurred", 65, results)
          243 
       
      ~/miniconda3/envs/demo/lib/python3.8/site-packages/pymongo/errors.py in __init__(self, error, code, details, max_wire_version)
          155         error_labels = None
          156         if details is not None:
      --> 157             error_labels = details.get('errorLabels')
          158         super(OperationFailure, self).__init__(
          159             _format_detailed_error(error, details), error_labels=error_labels)
       
      AttributeError: 'str' object has no attribute 'get'
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shane.harvey Shane Harvey
              Reporter:
              gimperiale Guido Imperiale
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: