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
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
|
a18953c to
b476518
Compare
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 significantly refactors the authentication handling and connection string construction in the
mssql_pythonpackage. The main improvements include migrating from string-based to dictionary-based parameter handling, consolidating authentication logic, and simplifying sensitive parameter removal. These changes modernize the codebase, reduce redundant parsing, and make it easier to extend or maintain authentication features.Authentication and connection string processing improvements:
mssql_python/auth.py,mssql_python/connection.py).UID,PWD,Trusted_Connection, andAuthentication) by using a canonical set and dictionary operations, ensuring robust sanitization before ODBC handoff (mssql_python/auth.py,mssql_python/connection.py).API and codebase modernization:
Connection._construct_connection_stringto return both the constructed string and the normalized parameter dictionary, enabling downstream logic to avoid reparsing and to use normalized parameters directly (mssql_python/connection.py)._construct_connection_string, ensuring continued correctness and coverage (tests/test_003_connection.py).Cleanup and removal of legacy code:
mssql_python/auth.py,mssql_python/connection.py,tests/test_008_auth.py).Overall, these changes streamline authentication handling, reduce parsing complexity, and lay a stronger foundation for future enhancements.