Skip to content

FIX: Strip stale auth fields from pycore_context after token acquisition in bulkcopy#488

Open
bewithgaurav wants to merge 4 commits intomainfrom
bewithgaurav/fix-bulkcopy-entra-auth-cleanup
Open

FIX: Strip stale auth fields from pycore_context after token acquisition in bulkcopy#488
bewithgaurav wants to merge 4 commits intomainfrom
bewithgaurav/fix-bulkcopy-entra-auth-cleanup

Conversation

@bewithgaurav
Copy link
Collaborator

@bewithgaurav bewithgaurav commented Mar 26, 2026

Work Item / Issue Reference

AB#43402
AB#43408

GitHub Issue: #<ISSUE_NUMBER>

Summary

Problem

cursor.bulkcopy() acquires a fresh Azure AD token and sets pycore_context["access_token"], but leaves the original authentication, user_name, and password keys from the parsed connection string. py-core's validator rejects access_token combined with those fields (ODBC parity).

Affects: ActiveDirectoryDefault, ActiveDirectoryInteractive, ActiveDirectoryDeviceCode.

Fix

Pop authentication, user_name, and password from pycore_context after setting access_token — the token is the sole credential for the py-core connection.

Companion PR

mssql-rs PR replaces a panic with a proper error for the case where no token factory is registered (ADIntegrated, ADPassword).

bulkcopy() acquires a fresh Azure AD token and sets access_token in
the pycore_context dict, but left authentication/user_name/password
from the original connection string.  py-core's validator rejects
access_token combined with those fields (ODBC parity).

Pop authentication, user_name, and password after setting access_token.
@github-actions
Copy link

github-actions bot commented Mar 26, 2026

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

77%


📈 Total Lines Covered: 5756 out of 7423
📁 Project: mssql-python


Diff Coverage

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

No lines with coverage information in this diff.


📋 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.pybind.ddbc_bindings.cpp: 70.4%
mssql_python.row.py: 70.5%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.connection.connection.cpp: 75.3%
mssql_python.__init__.py: 77.1%
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

@github-actions github-actions bot added the pr-size: medium Moderate update size label Mar 26, 2026
@bewithgaurav bewithgaurav marked this pull request as ready for review March 26, 2026 10:52
Copilot AI review requested due to automatic review settings March 26, 2026 10:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes cursor.bulkcopy() Azure AD authentication by ensuring that, after acquiring an access token, the py-core connection context does not retain stale connection-string credential fields that py-core rejects.

Changes:

  • Strip authentication, user_name, and password from pycore_context after setting access_token in Cursor.bulkcopy().
  • Add a focused unit test validating credential field cleanup when _auth_type triggers token acquisition (and verifying SQL-auth passthrough when _auth_type is unset).

Reviewed changes

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

File Description
mssql_python/cursor.py Removes stale auth/credential keys from pycore_context when access_token is used for bulkcopy’s py-core connection.
tests/test_020_bulkcopy_auth_cleanup.py Adds regression tests to assert the py-core context only contains token credentials for AAD bulkcopy.

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

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.

2 participants