azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Python 3.14: batch module argument loading fails due to typing/union handling in _command_type.py

Open YangAn-microsoft opened this issue 7 months ago • 2 comments

Summary

Doc generation fails on Python 3.14 when running ExportCommands.py.

Environment

  • Repo: Azure/azure-cli
  • OS: Windows
  • Python (failing): 3.14.4
  • Python (working): 3.13.13

Repro steps

  1. Activate env314.
  2. Ensure PYTHONPATH includes local knack checkout.
  3. Run: python ExportCommands.py ./doc

Actual result

The run fails during command argument loading with:

AttributeError: module 'azure.batch.models' has no attribute 'bool | None'

Trace location includes:

  • azure-cli/src/azure-cli/azure/cli/command_modules/batch/_command_type.py:838
  • azure-cli/src/azure-cli/azure/cli/command_modules/batch/_command_type.py:41

Expected result

Doc generation completes successfully.

Comparison

  • Python 3.13.13: succeeds (Export finished, help files generated)
  • Python 3.14.4: fails with the error above

Additional output seen in failing run

  • Error loading command module acs: deadlock detected by _ModuleLock('requests.structures')
  • Error loading command module containerapp: deadlock detected by _ModuleLock('requests.structures')

YangAn-microsoft avatar Apr 29 '26 04:04 YangAn-microsoft

Thank you for opening this issue, we will look into it.

yonzhan avatar Apr 29 '26 04:04 yonzhan

Update after investigation:

This does not appear to be specific to doc generation itself.

What we verified:

  • Python 3.13.13: TestBatchLoader::test_batch_load_arguments passes
  • Python 3.14.4: the same test fails
  • The original ExportCommands.py failure is just one caller that triggers the same Batch command-loading path

Narrow repro:

  • env313/Scripts/python.exe -m pytest src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_commands.py::TestBatchLoader::test_batch_load_arguments -v --tb=short
    • passes
  • env314/Scripts/python.exe -m pytest src/azure-cli/azure/cli/command_modules/batch/tests/latest/test_batch_commands.py::TestBatchLoader::test_batch_load_arguments -v --tb=short
    • fails

Current 3.14 failure:

  • AttributeError: module 'azure.batch.models' has no attribute 'VirtualMachineConfiguration | None'

Owning code path:

  • src/azure-cli/azure/cli/command_modules/batch/_command_type.py
  • specifically the Batch model introspection / flattening logic used to build CLI arguments

Interpretation:

  • Python 3.14 changed typing/union representations
  • the Batch module relies on brittle typing introspection/string handling
  • doc generation exposed it first, but the underlying bug is in Batch runtime argument loading, not in the docs pipeline specifically

YangAn-microsoft avatar Apr 30 '26 01:04 YangAn-microsoft