FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FIX: Credential instance cache by jahnvi480 · Pull Request #483 · microsoft/mssql-python · GitHub

FIX: Credential instance cache - #483

Merged
Jahnvi Thakkar (jahnvi480) merged 11 commits into
mainfrom
jahnvi/entra_cache
Apr 6, 2026
Merged

FIX: Credential instance cache#483
Jahnvi Thakkar (jahnvi480) merged 11 commits into
mainfrom
jahnvi/entra_cache

Conversation

Jahnvi Thakkar (jahnvi480) commented Mar 23, 2026
edited by azure-boards Bot
Loading

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

AB#43254

GitHub Issue: #388


Summary

This pull request introduces credential instance caching for Azure Active Directory (AAD) authentication in the mssql_python package, improving performance by reusing credential objects instead of creating new ones for each token request. It also adds comprehensive tests for the caching logic and edge cases, and includes a new benchmark script to measure the performance impact of credential caching.

Credential instance caching and logic changes:

  • Added a module-level credential cache (_credential_cache) and lock in auth.py to reuse Azure Identity credential instances per authentication type, enabling the SDK's in-memory token cache and reducing redundant token acquisitions. (mssql_python/auth.py)
  • Modified AADAuth.get_raw_token to use the cached credential instance rather than creating a new one each call, ensuring efficient token reuse. (mssql_python/auth.py )

Testing improvements:

  • Added a pytest fixture to clear the credential cache between tests, ensuring test isolation. (tests/test_008_auth.py )
  • Introduced a new TestCredentialInstanceCache class with tests verifying credential reuse, separation by auth type, and cache state. (tests/test_008_auth.py)
  • Added tests for error handling and edge cases, including missing Azure libraries, authentication errors, and unusual connection string parameter cases. (tests/test_008_auth.py )

Benchmarking:

  • Added a new benchmark script (benchmarks/bench_credential_cache.py) to measure and compare the performance of credential caching versus the previous behavior of creating new credentials for every token request. (benchmarks/bench_credential_cache.py)

Copilot AI review requested due to automatic review settings March 23, 2026 09:28
github-actions Bot added the pr-size: medium Moderate update size label Mar 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

This PR adds module-level caching of Azure Identity credential instances in mssql_python AAD auth flows to reduce repeated credential construction and enable Azure Identity’s in-memory token caching, along with new tests and a benchmark for measuring the impact.

Changes:

  • Added a module-level credential instance cache (with locking) used by AADAuth._acquire_token() / get_raw_token().
  • Expanded auth test coverage to validate credential reuse and additional error/edge paths.
  • Added a benchmark script to compare “new credential per call” vs “cached credential instance” token acquisition.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
mssql_python/auth.py Introduces a global credential-instance cache guarded by a lock and updates token acquisition to reuse credentials.
tests/test_008_auth.py Adds cache-clearing fixture and new tests for credential reuse, import-error handling, and edge cases.
benchmarks/bench_credential_cache.py Adds a standalone benchmark script to quantify the performance effect of credential-instance caching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

github-actions Bot commented Mar 23, 2026
edited
Loading

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

78%


📈 Total Lines Covered: 6619 out of 8399
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/auth.py (100%)

Summary

  • Total: 7 lines
  • Missing: 0 lines
  • Coverage: 100%

📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 67.8%
mssql_python.row.py: 70.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 73.9%
mssql_python.pybind.connection.connection.cpp: 75.3%
mssql_python.__init__.py: 77.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.connection.py: 85.2%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

Jahnvi Thakkar (jahnvi480) merged commit 2398ffd into main Apr 6, 2026
31 checks passed
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

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL