FIX: Avoid parsing connection string multiple times in auth path (#580)#590
Open
jahnvi480 wants to merge 1 commit into
Open
FIX: Avoid parsing connection string multiple times in auth path (#580)#590jahnvi480 wants to merge 1 commit into
jahnvi480 wants to merge 1 commit into
Conversation
_construct_connection_string now returns the normalized parameter dict alongside the connection string. Auth helpers in auth.py read keys directly from the dict instead of re-splitting the raw string. Key changes: - _construct_connection_string returns (str, Dict[str, str]) - process_connection_string removed; Connection.__init__ calls process_auth_parameters, remove_sensitive_params, get_auth_token and _ConnectionStringBuilder directly - extract_auth_type and process_auth_parameters share a single _AUTH_TYPE_MAP; no duplicated mapping logic - _SENSITIVE_KEYS promoted to module-level frozenset - auth.py no longer imports _ConnectionStringBuilder Net: -195 lines, one parse per connect instead of three.
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Entra ID auth handling path so the connection string is parsed only once. Connection._construct_connection_string now returns both the built string and the normalized parameter dict, which is then passed directly to the auth helpers; process_connection_string (and the duplicate auth parsing it contained) is removed.
Changes:
_construct_connection_stringreturns(conn_str, normalized_params);Connection.__init__reuses the parsed dict for auth handling instead of regex-checking and re-parsing the string.auth.pyis reworked to operate on dicts:process_auth_parametersandextract_auth_typetake a parsed dict,remove_sensitive_paramsfilters a dict via the new_SENSITIVE_KEYS, and_AUTH_TYPE_MAPcentralizes the auth value→short-name mapping.process_connection_stringis removed.- Tests updated to the new dict-based signatures; the obsolete
TestProcessConnectionString*suites and the empty/no-equals-sign edge cases are dropped in favor of dict-input edge cases.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| mssql_python/auth.py | Replaces string-list APIs with dict-based ones; removes process_connection_string; adds _SENSITIVE_KEYS and _AUTH_TYPE_MAP. |
| mssql_python/connection.py | Uses the parsed param dict for auth handling; switches _construct_connection_string to return a tuple and builds the sanitized string via _ConnectionStringBuilder. |
| tests/test_003_connection.py | Updates _construct_connection_string call sites to unpack the new tuple. |
| tests/test_008_auth.py | Migrates tests to dict-based APIs; removes process_connection_string tests and obsolete edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.build._deps.simdutf-src.src.haswell.implementation.cpp: 0.4%
mssql_python.pybind.build._deps.simdutf-src.src.implementation.cpp: 6.7%
mssql_python.pybind.build._deps.simdutf-src.include.simdutf.implementation.h: 10.4%
mssql_python.pybind.build._deps.simdutf-src.include.simdutf.scalar.utf16_to_utf8.utf16_to_utf8.h: 25.3%
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 59.7%
mssql_python.pybind.build._deps.simdutf-src.include.simdutf.internal.isadetection.h: 65.3%
mssql_python.row.py: 70.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 74.2%🔗 Quick Links
|
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.
Work Item / Issue Reference
Summary
This pull request refactors and modernizes the authentication and connection string handling logic for Entra ID (Azure AD) authentication in the
mssql_pythonpackage. The changes transition from string-based connection parameter processing to using normalized parameter dictionaries, improving code clarity, maintainability, and security. The update also streamlines Entra ID token handling and ensures sensitive information is managed more robustly.Authentication and connection string handling improvements:
process_auth_parametersand related functions to operate on parsed parameter dictionaries instead of raw parameter lists, making the code more robust and less error-prone._SENSITIVE_KEYSand_AUTH_TYPE_MAPfor centralized management of sensitive parameters and authentication type mappings.remove_sensitive_paramsto filter sensitive keys from parameter dictionaries rather than string lists.Connection initialization and construction:
connection.pyto use the parsed parameter dictionary throughout authentication handling, reducing redundant parsing and improving logic clarity._construct_connection_stringto return both the constructed connection string and the normalized parameter dictionary, and updated all usages and tests accordingly.Code cleanup and test updates:
_construct_connection_string.