Reorganize TLS options: implement PREFERRED/REQUIRED SSL mode behavior#1234
Merged
Conversation
Agent-Logs-Url: https://github.com/PyMySQL/PyMySQL/sessions/d0cfb9b3-3558-4762-a4ff-6c575f1e6dc7 Co-authored-by: methane <199592+methane@users.noreply.github.com>
Agent-Logs-Url: https://github.com/PyMySQL/PyMySQL/sessions/d0cfb9b3-3558-4762-a4ff-6c575f1e6dc7 Co-authored-by: methane <199592+methane@users.noreply.github.com>
Agent-Logs-Url: https://github.com/PyMySQL/PyMySQL/sessions/d0cfb9b3-3558-4762-a4ff-6c575f1e6dc7 Co-authored-by: methane <199592+methane@users.noreply.github.com>
…in test Agent-Logs-Url: https://github.com/PyMySQL/PyMySQL/sessions/d0cfb9b3-3558-4762-a4ff-6c575f1e6dc7 Co-authored-by: methane <199592+methane@users.noreply.github.com>
…variable Agent-Logs-Url: https://github.com/PyMySQL/PyMySQL/sessions/d0cfb9b3-3558-4762-a4ff-6c575f1e6dc7 Co-authored-by: methane <199592+methane@users.noreply.github.com>
Agent-Logs-Url: https://github.com/PyMySQL/PyMySQL/sessions/d0cfb9b3-3558-4762-a4ff-6c575f1e6dc7 Co-authored-by: methane <199592+methane@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add option to emulate ssl_mode=REQUIRED in MySQL
Reorganize TLS options: implement PREFERRED/REQUIRED SSL mode behavior
May 7, 2026
methane
reviewed
May 8, 2026
Agent-Logs-Url: https://github.com/PyMySQL/PyMySQL/sessions/034d531c-8a10-437a-92f6-b583bfb8c1f7 Co-authored-by: methane <199592+methane@users.noreply.github.com>
methane
reviewed
May 8, 2026
Agent-Logs-Url: https://github.com/PyMySQL/PyMySQL/sessions/665ab407-7b48-4c25-a2b8-0e9a782ca994 Co-authored-by: methane <199592+methane@users.noreply.github.com>
Updated changelog to reflect breaking changes in v1.2.0.
This was referenced May 8, 2026
methane
pushed a commit
that referenced
this pull request
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PyMySQL had no way to emulate MySQL's
ssl_mode=REQUIRED, andssl_disabledwas effectively a no-op. This reorganizes TLS behavior around a clear priority order without adding new options.Behavior
Evaluated in order:
ssl_disabled=True→ prohibit SSLssl,ssl_ca,ssl_cert,ssl_key,ssl_key_password,ssl_verify_cert,ssl_verify_identity) → REQUIRED: raisesOperationalError(CR_SSL_CONNECTION_ERROR)if the server doesn't advertiseCLIENT.SSLChanges
connections.pyself._ssl_requiredto distinguish REQUIRED vs PREFERRED at connect timeSSLContextvia_create_ssl_ctx({})when no SSL options are given and thesslmodule is available_request_authentication: refactored into aclient_flags/_do_sslpattern —CLIENT.SSLis added to the handshake flags only when the SSL upgrade actually happens (needed for PREFERRED, already set for REQUIRED); raises on REQUIRED + no server SSL; falls back silently for PREFERREDtests/test_connection.py: new tests covering PREFERRED setup, REQUIRED error path (with CA context assertion), and PREFERRED fallbackCHANGELOG.md: documents the behavior change