Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyop is incompatible with PyMongo 4+ #51

Closed
niheconomoum opened this issue Sep 6, 2023 · 1 comment · Fixed by #52
Closed

pyop is incompatible with PyMongo 4+ #51

niheconomoum opened this issue Sep 6, 2023 · 1 comment · Fixed by #52
Assignees
Labels

Comments

@niheconomoum
Copy link
Contributor

niheconomoum commented Sep 6, 2023

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.

@niheconomoum niheconomoum self-assigned this Sep 6, 2023
@niheconomoum
Copy link
Contributor Author

Issue #48 might be related.

niheconomoum added a commit to niheconomoum/pyop that referenced this issue Sep 7, 2023
Pin pyop to the latest version of PyMongo 3.x until it has completely
migrated to PyMongo 4.  Most of the key new methods and options from
PyMongo 4.0 are backported in PyMongo 3.12, making migration much
easier.

Closes IdentityPython#51
c00kiemon5ter pushed a commit that referenced this issue Sep 29, 2023
Pin pyop to the latest version of PyMongo 3.x until it has completely
migrated to PyMongo 4.  Most of the key new methods and options from
PyMongo 4.0 are backported in PyMongo 3.12, making migration much
easier.

Closes #51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant