Skip to content

[Core] Fix #33996: Eagerly import requests and msal in identity.py to prevent Python 3.14 import-lock deadlock - #9

Draft
a0x1ab with Copilot wants to merge 2 commits into
devfrom
copilot/fix-automated-review-issues
Draft

[Core] Fix #33996: Eagerly import requests and msal in identity.py to prevent Python 3.14 import-lock deadlock#9
a0x1ab with Copilot wants to merge 2 commits into
devfrom
copilot/fix-automated-review-issues

Conversation

Copilot AI commented Aug 27, 2026

Copy link
Copy Markdown

Python 3.14 raises _DeadlockError when background threads race to lazily import modules whose import-lock ordering creates a cycle (e.g. requests.structures). Pre-loading requests and msal on the main thread in identity.py eliminates the race.

Related command
az login (and any command that triggers authentication via azure.cli.core.auth.identity)

Description

  • auth/identity.py: Add eager top-level imports of requests and msal with # pylint: disable=unused-import, accompanied by a comment explaining the Python 3.14 deadlock rationale.
  • tests/test_auth_eager_import.py: New regression test that evicts the relevant modules from sys.modules, re-imports azure.cli.core.auth.identity, and asserts that requests, requests.structures, and msal are all present in sys.modules afterward — guarding against the eager imports being silently dropped in the future.

Testing Guide

python -m pytest src/azure-cli-core/azure/cli/core/tests/test_auth_eager_import.py -v

History Notes
{Core} Fix Python 3.14 _DeadlockError caused by lazy import of requests/msal in background threads


This checklist is used to make sure that common guidelines for a pull request are followed.

Co-authored-by: a0x1ab <59631311+a0x1ab@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement changes from automated review feedback [Core] Fix #33996: Eagerly import requests and msal in identity.py to prevent Python 3.14 import-lock deadlock Aug 27, 2026
Copilot AI requested a review from a0x1ab August 27, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants