Skip to content

skip ssl import if not available #3078

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

Merged
merged 5 commits into from
Mar 14, 2025
Merged

skip ssl import if not available #3078

merged 5 commits into from
Mar 14, 2025

Conversation

dicej
Copy link
Contributor

@dicej dicej commented Dec 18, 2023

Pull Request check-list

Please make sure to review and check all of these items:

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?
  • Was the change added to CHANGES file?

NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.

Description of change

utils.py has support for detecting whether the ssl module is available, and we can use this to omit SSL-specific funcionality while still providing other features (e.g. unencrypted connections).

Prior to this patch, the connection.py modules both triggered an ImportError due to unconditional imports of the ssl module. Now, we check utils.SSL_AVAILABLE prior to attempting the import and only raise an error later if (and only if) the application requests an encrypted connection. This helps support platforms such as wasm32-wasi where the ssl module is not built by default.

Ideally, this would be tested in CI using a Python built without ssl support. I'm not sure how feasible that is, though; I'm open to guidance on that aspect.

@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (2f88840) 91.84% compared to head (b94b105) 91.83%.
Report is 8 commits behind head on master.

Files Patch % Lines
redis/asyncio/connection.py 63.63% 4 Missing ⚠️
redis/connection.py 66.66% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3078      +/-   ##
==========================================
- Coverage   91.84%   91.83%   -0.01%     
==========================================
  Files         128      128              
  Lines       33232    33283      +51     
==========================================
+ Hits        30523    30567      +44     
- Misses       2709     2716       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@petyaslavova
Copy link
Collaborator

Hi @dicej, can you please update your code to follow the pattern set in https://github.com/redis/redis-py/blob/master/redis/client.py for ssl import and type hints and fix the conflicts?

Copy link
Collaborator

@petyaslavova petyaslavova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested changes are posted in previous comment.

@dicej
Copy link
Contributor Author

dicej commented Mar 12, 2025

Hi @dicej, can you please update your code to follow the pattern set in https://github.com/redis/redis-py/blob/master/redis/client.py for ssl import and type hints and fix the conflicts?

Done, and tested on wasm32-wasi (which does not have an ssl module).

Copy link
Collaborator

@petyaslavova petyaslavova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dicej please fix the linter errors and apply requested changes

@petyaslavova petyaslavova merged commit 9251650 into redis:master Mar 14, 2025
37 checks passed
petyaslavova added a commit to rohansingh/redis-py that referenced this pull request Mar 25, 2025
* skip `ssl` import if not available

Signed-off-by: Joel Dice <[email protected]>

* address review feedback and fix lint errors

Signed-off-by: Joel Dice <[email protected]>

* remove TYPE_CHECKING clause from ssl conditional

Signed-off-by: Joel Dice <[email protected]>

---------

Signed-off-by: Joel Dice <[email protected]>
Co-authored-by: petyaslavova <[email protected]>
@petyaslavova petyaslavova added the maintenance Maintenance (CI, Releases, etc) label Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance (CI, Releases, etc)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants