Details
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
- Install the Python 3.x SDK
- 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
For Gerrit Dashboard: PYCBC-970 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
132011,3 | PYCBC-970: shortcircuit docstring reads in optimised mode | master | couchbase-python-client | Status: MERGED | +2 | +1 |