-
Notifications
You must be signed in to change notification settings - Fork 36
Description
TL;DR—Work around this problem by installing pymongo==3.13 after installing pyop.
PyMongo 3 depreciated MongoReplicaSetClient, and PyMongo 4 removed it (cf. https://github.com/mongodb/mongo-python-driver/blob/master/doc/migrate-to-pymongo4.rst). However, pyop still refers to MongoReplicaSetClient, causing pyop to throw an AttributeError when configured to use a clustered MongoDB instance.
For example, I'm using pyop via SATOSA's openid_connect_frontend with an Amazon DocumentDB cluster (cf., https://github.com/IdentityPython/SATOSA/blob/master/doc/one-to-many.md, https://github.com/IdentityPython/SATOSA/blob/master/example/plugins/frontends/openid_connect_frontend.yaml.example, and https://docs.aws.amazon.com/documentdb/latest/developerguide/connect_programmatically.html). The database URI looks something like this:
mongodb://<sample-user>:<password>@sample-cluster.node.us-east-1.docdb.amazonaws.com:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false
However, when SATOSA starts, I get the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/satosa/proxy_server.py", line 192, in make_app
res1 = WsgiApplication(satosa_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/satosa/proxy_server.py", line 118, in __init__
super().__init__(config)
File "/usr/local/lib/python3.11/site-packages/satosa/base.py", line 45, in __init__
frontends = load_frontends(self.config, self._auth_req_callback_func,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/satosa/plugin_loader.py", line 68, in load_frontends
frontend_modules = _load_plugins(config.get("CUSTOM_PLUGIN_MODULE_PATHS"), config["FRONTEND_MODULES"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/satosa/plugin_loader.py", line 181, in _load_plugins
instance = module_class(callback, internal_attributes, module_config, base_url,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/satosa/frontends/openid_connect.py", line 77, in __init__
StorageBase.from_uri(db_uri, db_name="satosa", collection="authz_codes")
File "/usr/local/lib/python3.11/site-packages/pyop/storage.py", line 72, in from_uri
return MongoWrapper(
^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pyop/storage.py", line 127, in __init__
self._db = MongoDB(db_uri, db_name=db_name, **mongo_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pyop/storage.py", line 311, in __init__
connection_factory = pymongo.MongoReplicaSetClient
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pymongo' has no attribute 'MongoReplicaSetClient'
Downgrading to PyMongo 3.13 works around this problem. Long term, pyop should migrate to PyMongo 4 or newer.