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

Can't pickle BulkWriteError

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

      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'
      

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            gimperiale Guido Imperiale
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: