Skip to content

[VM Repair] Fix Python 3.12+ compatibility: replace deprecated datetime.utcnow() - #10190

Open
EdwinBernal1 wants to merge 3 commits into
Azure:mainfrom
EdwinBernal1:edwin/vm-repair-py312-compat
Open

[VM Repair] Fix Python 3.12+ compatibility: replace deprecated datetime.utcnow()#10190
EdwinBernal1 wants to merge 3 commits into
Azure:mainfrom
EdwinBernal1:edwin/vm-repair-py312-compat

Conversation

@EdwinBernal1

@EdwinBernal1 EdwinBernal1 commented Aug 7, 2026

Copy link
Copy Markdown
Member

🤖 PR Validation — ️✔️ All clear

Breaking Changes
️✔️ None

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

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install azdev required)
  • My extension version conforms to the Extension version schema

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.json automatically.
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-button

Description

datetime.utcnow() is deprecated as of Python 3.12 and scheduled for removal. This
replaces 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)
  • timezone added to the datetime imports.

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 the
same UTC wall-clock value.

Also declares Python 3.12 support in setup.py classifiers and adds
test_py312_compat.py, a static regression guard that fails if
utcnow/utcfromtimestamp/imp/asyncore/distutils reappear in shipped code.

Source: ADO PBI 38927108 (VMRepair Python 3.12+ Forward Compatibility).

Testing Guide

  • New unit test test_py312_compat.py (static scan) — passes.
  • flake8 clean; pylint 10.00/10 on the changed files.
  • scripts/ci/test_index.py structural checks pass; src/index.json not modified.

History

  • setup.py VERSION: 2.2.1 -> 2.2.2
  • HISTORY.rst entry added: yes

  • The PR title and description conform to the guidelines.
  • I have merged the latest main branch into my branch (merge commit included).
  • I have tested the change locally (unit test + style).

General Guidelines

  • Have you run azdev style vm-repair locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install azdev required)

Extension Publish Checklist

Copilot AI lite review requested due to automatic review settings August 7, 2026 15:02
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

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() with datetime.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.2 and 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 thread src/vm-repair/azext_vm_repair/tests/latest/test_py312_compat.py
Comment thread src/vm-repair/setup.py Outdated
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',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

make the request update

@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
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
EdwinBernal1 force-pushed the edwin/vm-repair-py312-compat branch from ee5f457 to 17dbafa Compare August 7, 2026 15:26
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
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.
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
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).
@a0x1ab

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants