[VM Repair] Fix Python 3.12+ compatibility: replace deprecated datetime.utcnow() - #10190
Open
EdwinBernal1 wants to merge 3 commits into
Open
[VM Repair] Fix Python 3.12+ compatibility: replace deprecated datetime.utcnow()#10190EdwinBernal1 wants to merge 3 commits into
EdwinBernal1 wants to merge 3 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
microsoft-github-policy-service
Bot
requested review from
Julie Zhu (yanzhudd) and
Yong Zhang (yonzhan)
August 7, 2026 15:04
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the vm-repair Azure CLI extension to remain compatible with Python 3.12+ by replacing deprecated datetime.utcnow() usage with timezone-aware UTC timestamps, and adds a static regression test to prevent reintroducing Python 3.12-removed/deprecated APIs.
Changes:
- Replace
datetime.utcnow()withdatetime.now(timezone.utc)in name/timestamp generation paths. - Add a static unit test that scans shipped source for banned Python 3.12+ incompatible APIs.
- Bump extension version to
2.2.2and add Python 3.12 classifier + HISTORY entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/vm-repair/setup.py | Bumps version and updates PyPI classifiers to include Python 3.12. |
| src/vm-repair/HISTORY.rst | Adds release notes entry for the Python 3.12+ compatibility change. |
| src/vm-repair/azext_vm_repair/tests/latest/test_py312_compat.py | Adds a static scan test to block reintroduction of removed/deprecated APIs. |
| src/vm-repair/azext_vm_repair/custom.py | Switches timestamp generation to timezone-aware UTC datetime. |
| src/vm-repair/azext_vm_repair/_validators.py | Switches timestamp generation to timezone-aware UTC datetime in validators. |
Comment on lines
22
to
26
| 'Programming Language :: Python :: 3.5', | ||
| 'Programming Language :: Python :: 3.6', | ||
| 'Programming Language :: Python :: 3.12', | ||
| 'Programming Language :: Python :: 3.13', | ||
| 'License :: OSI Approved :: MIT License', |
Member
Author
There was a problem hiding this comment.
make the request update
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
…3.12+ Replaces deprecated datetime.utcnow() with timezone-aware datetime.now(timezone.utc) in custom.py (2 sites) and _validators.py (2 sites) and adds timezone to the datetime imports. Generated timestamp strings are unchanged. Bumps VERSION 2.2.1 -> 2.2.2, declares Python 3.12 support, and adds a HISTORY.rst entry. Adds test_py312_compat.py, a static regression guard that bans utcnow/utcfromtimestamp/imp/asyncore/distutils in shipped code. Addresses ADO PBI 38927108 (VMRepair Python 3.12+ Forward Compatibility).
EdwinBernal1
force-pushed
the
edwin/vm-repair-py312-compat
branch
from
August 7, 2026 15:26
ee5f457 to
17dbafa
Compare
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
Removes stale Python 2/2.7 and EoL 3.4-3.6 classifiers and adds 3.9-3.11, matching the repo convention (e.g. discovery/napster). Metadata-only; no behavior change.
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
…/3.14) pkgutil.get_loader() is deprecated in Python 3.12 and removed in 3.14, and Loader.load_module() is deprecated since 3.12. Replace both bundled-driver-script path lookups in repair_utils.py with importlib.util.find_spec(). Extend the test_py312_compat static guard to ban pkgutil.get_loader/find_loader/ImpImporter and platform.dist(). Completes the Python 3.12+ breaking-API migration for PBI 38927108 (the extension does not use imp/asyncore/asynchat/distutils/platform.dist; the FrameLocalsProxy Phase 2 concern is already handled via dict(args.locals) in command param capture).
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
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.
🤖 PR Validation — ️✔️ All clear
This checklist is used to make sure that common guidelines for a pull request are followed.
Related command
General Guidelines
azdev style <YOUR_EXT>locally? (pip install azdevrequired)python scripts/ci/test_index.py -qlocally? (pip install azdevrequired)For new extensions:
About Extension Publish
There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update
src/index.jsonautomatically.You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify
src/index.json.Related command
az vm repair create/az vm repair repair-and-restore/az vm repair repair-buttonDescription
datetime.utcnow()is deprecated as of Python 3.12 and scheduled for removal. Thisreplaces all 4 usages in vm-repair with the timezone-aware
datetime.now(timezone.utc)so the extension stays forward-compatible:_validators.py— 2 sites (validate_create,validate_repair_and_restore)custom.py— 2 sites (repair_and_restore,repair_button)timezoneadded to thedatetimeimports.The generated timestamp strings (used for the repair VM, copied disk, and repair
resource group names) are unchanged —
.strftime('%Y%m%d%H%M%S')produces thesame UTC wall-clock value.
Also declares Python 3.12 support in
setup.pyclassifiers and addstest_py312_compat.py, a static regression guard that fails ifutcnow/utcfromtimestamp/imp/asyncore/distutilsreappear in shipped code.Source: ADO PBI 38927108 (VMRepair Python 3.12+ Forward Compatibility).
Testing Guide
test_py312_compat.py(static scan) — passes.scripts/ci/test_index.pystructural checks pass;src/index.jsonnot modified.History
General Guidelines
azdev style vm-repairlocally? (pip install azdevrequired)python scripts/ci/test_index.py -qlocally? (pip install azdevrequired)Extension Publish Checklist