-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Encryption, pymongocrypt
-
None
When pymongocrypt fails to find the libmongocrypt dll it raises an OSError:
python -c 'import pymongo' Traceback (most recent call last): File "<string>", line 1, in <module> File "/Users/shane/git/mongo-python-driver/pymongo/__init__.py", line 77, in <module> from pymongo.collection import ReturnDocument File "/Users/shane/git/mongo-python-driver/pymongo/collection.py", line 29, in <module> from pymongo import (common, File "/Users/shane/git/mongo-python-driver/pymongo/common.py", line 31, in <module> from pymongo.encryption_options import validate_auto_encryption_opts_or_none File "/Users/shane/git/mongo-python-driver/pymongo/encryption_options.py", line 20, in <module> import pymongocrypt File "/Users/shane/git/libmongocrypt/bindings/python/pymongocrypt/__init__.py", line 15, in <module> from pymongocrypt.binding import libmongocrypt_version, lib File "/Users/shane/git/libmongocrypt/bindings/python/pymongocrypt/binding.py", line 919, in <module> lib = ffi.dlopen(os.environ.get('PYMONGOCRYPT_LIB', 'mongocrypt')) File "/usr/local/Cellar/pypy3/7.0.0/libexec/lib_pypy/cffi/api.py", line 146, in dlopen lib, function_cache = _make_ffi_library(self, name, flags) File "/usr/local/Cellar/pypy3/7.0.0/libexec/lib_pypy/cffi/api.py", line 828, in _make_ffi_library backendlib = _load_backend_lib(backend, libname, flags) File "/usr/local/Cellar/pypy3/7.0.0/libexec/lib_pypy/cffi/api.py", line 823, in _load_backend_lib raise OSError(msg) OSError: ctypes.util.find_library() did not manage to locate a library called 'mongocrypt'
We can fix this in two ways:
- make pymongocrypt catch the OSError and add a new function to check if the library was loaded correctly called "is_initialized()". PyMongo can call is_initialized() when creating an AutoEncryptionOpts or ClientEncryption.
- make pymongo catch OSError when importing pymongocrypt. Later we can raise an informative error to the user about what went wrong.
I prefer option 1 because it abstracts libmongocrypt better; pymongo should not need to know or care that pymongocrypt uses CFFI.