Skip to content

Conversation

mpsijm
Copy link
Contributor

@mpsijm mpsijm commented Jun 12, 2025

When there is a mistake in the certificates configuration, PyMongo would give the following error:

pymongo.errors.ServerSelectionTimeoutError: module service_identity has no attribute SICertificateError, Timeout: 30s, Topology Description: <…> 

Because the except block expected non-existing errors, the error gets transformed to "module … has no attribute …". The errors in the service_identity have never had the SI prefix:
https://github.com/pyca/service-identity/blob/18.1.0/src/service_identity/exceptions.py
It looks like the errors were imported with an alias before, but this aliasing was (only partially) removed when rewriting to lazy imports in this commit:
42a08c4#diff-b277a2f4cfbb5decab333d0b90a08a4ad64b91fb1691ed8412b15949d1aaceee
The lazy imports were removed again in this commit, but the error remained:
49987e6#diff-b277a2f4cfbb5decab333d0b90a08a4ad64b91fb1691ed8412b15949d1aaceee
After changing the expected errors manually in my virtual environment, the error I received earlier turned into this, so I could continue debugging my certificates configuration:

pymongo.errors.ServerSelectionTimeoutError: […]: ("VerificationError(errors=[IPAddressMismatch(…)])",) (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <…> 

Most likely, the # type: ignore[misc] comment can now also be removed (but I have not set up this repository for development on my machine, so I'll let the automated checks be the judge of that).

When there is a mistake in the certificates configuration, PyMongo would give the following error: ``` pymongo.errors.ServerSelectionTimeoutError: module service_identity has no attribute SICertificateError, Timeout: 30s, Topology Description: <…> ``` Because the `except` block expected non-existing errors, the error gets transformed to "module … has no attribute …". The errors in the `service_identity` have never had the `SI` prefix: https://github.com/pyca/service-identity/blob/18.1.0/src/service_identity/exceptions.py It looks like the errors were imported with an alias before, but this aliasing was (only partially) removed when rewriting to lazy imports in this commit: mongodb@42a08c4#diff-b277a2f4cfbb5decab333d0b90a08a4ad64b91fb1691ed8412b15949d1aaceee The lazy imports were removed again in this commit, but the error remained: mongodb@49987e6#diff-b277a2f4cfbb5decab333d0b90a08a4ad64b91fb1691ed8412b15949d1aaceee Most likely, the `# type: ignore[misc]` comment can now also be removed.
@ShaneHarvey ShaneHarvey changed the title pyopenssl_context.py: Fix incorrect service_identity error names PYTHON-5414 Fix "module service_identity has no attribute SICertificateError" when using pyopenssl Jun 12, 2025
@ShaneHarvey ShaneHarvey self-requested a review June 12, 2025 17:07
@ShaneHarvey
Copy link
Member

ShaneHarvey commented Jun 12, 2025

Thanks for the detailed report and fix! It looks good to me but I'm going to see if I can add a regression test before merging.

@mpsijm
Copy link
Contributor Author

mpsijm commented Jun 12, 2025

Sounds good, thanks! If it helps coming up with the test: in the end, I had two mistakes in my configuration, I forgot which one triggered this code path (maybe it was both):

  • I was connecting to 127.0.0.1, rather than the domain name for which the Mongo server had a TLS certificate.
  • I forgot to set the authMechanism option to MONGODB-X509 (I did have tls, tlsCertificateKeyFile, and tlsCAFile set correctly).
@ShaneHarvey ShaneHarvey merged commit c2aefc2 into mongodb:master Jun 12, 2025
75 of 79 checks passed
@mpsijm mpsijm deleted the patch-1 branch June 13, 2025 05:20
@mpsijm
Copy link
Contributor Author

mpsijm commented Jun 13, 2025

I see that the regression test will be added in #2385 🙂 Thanks for merging! 😄 ❤️

ShaneHarvey pushed a commit to ShaneHarvey/mongo-python-driver that referenced this pull request Jun 13, 2025
…teError" when using pyopenssl (mongodb#2382) (cherry picked from commit c2aefc2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants