Uploaded image for project: 'Couchbase Python Client Library'
  1. Couchbase Python Client Library
  2. PYCBC-970

Python SDK assumes docstrings are available

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.0.1
    • 3.0.2
    • library
    • None
    • 1
    • SDK28: Txn Loop/Rb,PfQueryColl, June 8 - June 19

    Description

      Summary
      The Python SDK assumes that the docstrings for each function and class are always available, but in some circumstances these might not be, causing the SDK to crash immediately.

      Steps to Reproduce

      1. Install the Python 3.x SDK
      2. Import the couchbase SDK in optimized mode:

        python3 -OO -c "import couchbase"
        

      Expected Result
      The command to exit cleanly (i.e. with no error)

      Actual Result
      The command exits with an error and stacktrace:

      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/usr/local/lib/python3.7/site-packages/couchbase/__init__.py", line 1, in <module>
          import couchbase_core._bootstrap
        File "/usr/local/lib/python3.7/site-packages/couchbase_core/_bootstrap.py", line 34, in <module>
          import couchbase.exceptions as E
        File "/usr/local/lib/python3.7/site-packages/couchbase/exceptions.py", line 600, in <module>
          class ErrorContext(dict):
        File "/usr/local/lib/python3.7/site-packages/couchbase/exceptions.py", line 609, in ErrorContext
          @uncommitted
        File "/usr/local/lib/python3.7/site-packages/couchbase_core/supportability.py", line 19, in __new__
          message = cls.__doc__+"\n"
      TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
      

      Analysis
      The -OO flag on the python3 command triggers Python to interpret the code in optimized mode, where the docstrings are completely removed and are instead all None.
      The Python SDK doesn't account for this possibility and tries to concatenate the None with a string, causing the crash.
      The SDK instead needs to short-circuit this extra logic in this case, to prevent crashes, although it seems perfectly acceptable to have less descriptive errors etc if interpreted in this way.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          Ellis.Breen Ellis Breen added a comment -

          Hi, I have produced a fix for this and tested it locally with

          python -OO

          It should be installable via this command:

          pip install git+http://review.couchbase.org/couchbase-python-client@refs/changes/11/132011/2
          

          Hopefully will get this merged soon but feel free to try this.

          Ellis.Breen Ellis Breen added a comment - Hi, I have produced a fix for this and tested it locally with python -OO It should be installable via this command: pip install git+http: //review.couchbase.org/couchbase-python-client@refs/changes/11/132011/2 Hopefully will get this merged soon but feel free to try this.

          People

            Ellis.Breen Ellis Breen
            matt.carabine Matt Carabine
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty