[DevTest Labs] az lab vm create: Fix --expiration-date always failing with a datetime comparison error - #34066
Open
om singhal (Om-singhaI) wants to merge 1 commit into
Conversation
…ling with a datetime comparison error AAZDateTimeArg normalizes --expiration-date into an offset aware UTC timestamp before pre_operations runs, so _validate_expiration_date always parsed an offset aware datetime. It compared that against the naive datetime.datetime.utcnow(), which raises TypeError for every value, making the argument unusable. Compare against datetime.datetime.now(datetime.timezone.utc) instead. That also drops a utcnow() call deprecated since Python 3.12. Fixes Azure#31611
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Thank you for your contribution om singhal (@Om-singhaI)! We will review the pull request and get back to you soon. |
Copilot started reviewing on behalf of
om singhal (Om-singhaI)
September 11, 2026 07:45
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The fix and regression tests address the reported failure with no unresolved blocking issues.
Pull request overview
Fixes az lab vm create --expiration-date datetime comparison failures.
Changes:
- Uses timezone-aware UTC validation.
- Adds future, past, and omitted expiration-date tests.
File summaries
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/lab/validators.py |
Corrects expiration-date comparison. |
src/azure-cli/azure/cli/command_modules/lab/tests/latest/test_lab_validators.py |
Adds expiration-date validator coverage. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Collaborator
|
DevTest Labs |
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.
Related command
az lab vm create --expiration-dateDescription
--expiration-dateis unusable onaz lab vm create. Every date fails, which is what #31611 reports.By the time
_validate_expiration_dateruns,AAZDateTimeArghas already normalized the argument into a UTC timestamp, sinceAAZCommand._handlercallsformat_args()beforepre_operations. So the validator always parses an offset aware datetime. It compared that againstdatetime.datetime.utcnow(), which is naive, and Python won't compare the two.The validator does no I/O, so this reproduces on
devwith no Azure credentials. The snippet sets the argument up through the sameAAZCommandCtx.format_args()call the command goes through:Swap in
2030-06-17 22:00:00,2030-06-17 22:00:00+00:00or2030-06-17 22:00:00.000+00:00and the traceback is identical. Those are the four date strings from the issue, with the year bumped so the date is still in the future.I switched the comparison to
datetime.datetime.now(datetime.timezone.utc). That drops autcnow()call too, which has been deprecated since Python 3.12.Testing Guide
ExpirationDateValidatorTestintest_lab_validators.pysets the argument up the same way, then checks that a future date passes, a past date still raisesArgumentUsageError, and an omitted date is left alone. Revertvalidators.pyand both date tests fail with theTypeErrorabove.The recorded scenario tests never passed
--expiration-date, which is why none of them caught this. They still pass: