Skip to content

Fix apiVersionToFloat crashing on preview API versions with a sub-version - #1511

Open
Allan Oliveira (allan-oliveira) wants to merge 1 commit into
Azure:masterfrom
allan-oliveira:fix/invoke-preview-api-version-parsing
Open

Fix apiVersionToFloat crashing on preview API versions with a sub-version#1511
Allan Oliveira (allan-oliveira) wants to merge 1 commit into
Azure:masterfrom
allan-oliveira:fix/invoke-preview-api-version-parsing

Conversation

@allan-oliveira

Copy link
Copy Markdown

Summary

az devops invoke --api-version <X.Y-preview.N> fails with could not convert string to float: '<X.Y.N>'.

apiVersionToFloat only strips the literal -preview substring:

def apiVersionToFloat(apiVersion):
    apiVersion = apiVersion.replace('-preview', '')
    return float(apiVersion)

For an input like 7.1-preview.1, this leaves 7.1.1 behind (the sub-version suffix stays attached), which float() can't parse.

Fix

Split on -preview and keep only the part before it, so the whole preview marker (including any sub-version) is dropped:

def apiVersionToFloat(apiVersion):
    apiVersion = apiVersion.split('-preview')[0]
    return float(apiVersion)

This is the only call site of apiVersionToFloat in the codebase, and the parsed float is only used for a local version comparison against resource_location.max_version (line 91) — the original, unmodified api_version string is still passed through unchanged to the actual HTTP client call (line 103), so this only fixes the local comparison logic without touching wire behavior.

Test plan

  • Added azext_devops/tests/latest/team/test_invoke.py covering plain versions, X.Y-preview, X.Y-preview.N, and multi-digit sub-versions.
  • Manually verified the fixed function against the exact failing input from the linked issues.

Fixes #946
Fixes #1454

…sion

apiVersion.replace('-preview', '') only strips the literal "-preview"
substring, leaving a dangling ".N" suffix for versions like "7.1-preview.1"
(becomes "7.1.1"), which float() can't parse. Split on "-preview" instead
and keep only the part before it, so any preview sub-version is dropped
along with the marker.

Fixes Azure#946, Azure#1454
@allan-oliveira

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

Allow az devops invoke to support preview API versions [Bug] az devops invoke doesn't support preview API versions

1 participant