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

unicode(PyMongoError) fails with UnicodeDecodeError on Python 2

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.10
    • Affects Version/s: 3.8, 3.9
    • Component/s: API
    • Labels:
      None

      Repro on Python 2:

      >>> unicode(PyMongoError(u'unicode \U0001f40d'))
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      UnicodeDecodeError: 'ascii' codec can't decode byte 0xf0 in position 8: ordinal not in range(128)
      

      This regression was introduced in PyMongo 3.8 by PYTHON-1682.

      In PYTHON-1682 we made a change to ensure that str(PyMongoError(u'unicode \U0001f40d')) always returns a str in Python 2 (not a unicode). We should consider adding a PyMongoError._unicode_ so that unicode(PyMongoError(u'unicode \U0001f40d')) does not fail.

      For motivation see this issue: https://github.com/MongoEngine/mongoengine/pull/2147

      And this comment thread: https://github.com/mongodb/mongo-python-driver/commit/e7114087c7af87d804aaa6cdc3696a62c5d59d08#diff-83f588285a24ab0d1ee8a57f88312a6a

      And this comment thread: https://github.com/MongoEngine/mongoengine/pull/1428#issuecomment-521981230

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

              Created:
              Updated:
              Resolved: