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

Python 3.1.x pickle issues with bson.binary.Binary

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4
    • Affects Version/s: None
    • Component/s: None
    • None

      This is likely due to a pickle bug in python 3.1 but I haven't yet tracked down an appropriate ticket on bugs.python.org

      Unpickling a Binary object in 3.1 fails:

      Python 3.1.5 (default, Jul  9 2012, 22:15:20) 
      [GCC 4.5.3] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import pickle
      >>> from bson.binary import Binary
      >>> b = Binary(b'123', 2)
      >>> p = pickle.dumps(b)
      >>> p
      b'\x80\x03cbson.binary\nBinary\nq\x00X\x03\x00\x00\x00123q\x01\x85q\x02\x81q\x03}q\x04X\x10\x00\x00\x00_Binary__subtypeq\x05K\x02sb.'
      >>> pickle.loads(p)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib64/python3.1/pickle.py", line 1363, in loads
          encoding=encoding, errors=errors).load()
        File "bson/binary.py", line 135, in __new__
          "instance of %s" % (binary_type.__name__,))
      TypeError: data must be an instance of bytes
      

      No issues in 3.2:

      Python 3.2.3 (default, Jul  9 2012, 12:47:41) 
      [GCC 4.5.3] on linux2
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import pickle
      >>> from bson.binary import Binary
      >>> b = Binary(b'123', 2)
      >>> p = pickle.dumps(b)
      >>> p
      b'\x80\x03cbson.binary\nBinary\nq\x00C\x03123q\x01\x85q\x02\x81q\x03}q\x04X\x10\x00\x00\x00_Binary__subtypeq\x05K\x02sb.'
      >>> pickle.loads(p)
      Binary(b'123', 2)
      

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            bernie@mongodb.com Bernie Hackett
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: