{edge-action} Bugfix: edge action get version code and swap default version unsupported media type error#9445
Conversation
- Added Content-Type: application/json header to POST request - Expanded Accept header to include text/plain and */* for better compatibility - Resolves 'Unsupported Media Type' error when calling get-version-code - Added test case for get-version-code command The fix ensures proper HTTP headers are sent for the getVersionCode operation, which is a POST request with no body. Some Azure services require both Content-Type and Accept headers to be present even for empty-body requests.
…ension
- Add Content-Type and Accept headers to get-version-code and swap-default POST operations
- Add empty JSON body '{}' required by the API for POST operations without payload
- Add --output-directory parameter to get-version-code to decode and save zip files
- Comment out execution-filter CRUD test (service returns HTTP URLs in LRO headers, needs service-side fix)
- Re-record all passing tests
The root cause was that AAZ-generated code for POST operations without a request body
was not sending Content-Type header or empty body, causing the API to reject with 415.
|
| rule | cmd_name | rule_message | suggest_message |
|---|---|---|---|
| edge-action version get-version-code | cmd edge-action version get-version-code added parameter output_directory |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
CodeGen Tools Feedback CollectionThank you for using our CodeGen tool. We value your feedback, and we would like to know how we can improve our product. Please take a few minutes to fill our codegen survey |
|
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR fixes bugs in the edge-action extension related to "415 Unsupported Media Type" errors occurring in POST operations for get-version-code and swap-default commands.
Key changes:
- Added required HTTP headers (
Content-TypeandAccept) and empty JSON body to POST requests - Enhanced
get-version-codecommand with an optional--output-directoryparameter to decode and save version code as a zip file - Updated extension version from
1.0.0b1to1.0.0b2
Reviewed changes
Copilot reviewed 8 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/edge-action/setup.py | Bumped version to 1.0.0b2 |
| src/edge-action/HISTORY.rst | Added release notes for 1.0.0b2 documenting the bug fixes and new feature |
| src/edge-action/azext_edge_action/aaz/latest/edge_action/version/_get_version_code.py | Fixed HTTP headers/body for API request and added output directory functionality for decoding/saving zip files |
| src/edge-action/azext_edge_action/aaz/latest/edge_action/version/_swap_default.py | Fixed HTTP headers/body for API request |
| src/edge-action/azext_edge_action/tests/latest/test_edge_action.py | Added test for get-version-code command |
| src/edge-action/azext_edge_action/tests/latest/recordings/*.yaml | Updated test recordings with new test data and timestamps |
| try: | ||
| decoded_content = base64.b64decode(content) | ||
| except Exception as e: | ||
| from azure.cli.core.azclierror import ValidationError | ||
| raise ValidationError(f"Failed to decode base64 content: {str(e)}") |
There was a problem hiding this comment.
Using bare except Exception is too broad. Consider catching specific exception types (e.g., base64.binascii.Error for base64 decoding errors) or at minimum re-raising unexpected exceptions after logging them. This will make debugging easier and prevent masking unexpected errors.
| f.write(decoded_content) | ||
| logger.warning(f"Version code saved to: {output_file}") | ||
| return {"message": f"Version code saved to: {output_file}", "file": output_file} | ||
| except Exception as e: |
There was a problem hiding this comment.
Using bare except Exception is too broad here as well. Consider catching specific file I/O exceptions (e.g., IOError, OSError, PermissionError) to provide more precise error handling.
| except Exception as e: | |
| except (OSError, PermissionError) as e: |
|
[Release] Update index.json for extension [ edge-action-1.0.0b2 ] : https://dev.azure.com/msazure/One/_build/results?buildId=144845648&view=results |
This checklist is used to make sure that common guidelines for a pull request are followed.
Related command
{edge-action}
General Guidelines
azdev style <YOUR_EXT>locally? (pip install azdevrequired)python scripts/ci/test_index.py -qlocally? (pip install wheel==0.30.0required)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.