[azure-core] Fix format_url dropping trailing slash when URL template is query-string only#45366
[azure-core] Fix format_url dropping trailing slash when URL template is query-string only#45366
format_url dropping trailing slash when URL template is query-string only#45366Conversation
…string only Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
format_url dropping trailing slash when URL template is query-string only
|
/azp run python - tables - ci |
|
No pipelines are associated with this pull request. |
|
/azp run python - tables - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run python - storage - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@copilot our tables tests are failing with this change |
…only stubs Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
Fixed in commit The key logic: # Only strip trailing slash from base when stub has a path component.
# For query-string-only stubs (e.g. "?key=val"), preserve any trailing
# slash so it appears before the query string in the final URL.
if url.split("?", 1)[0]:
base = base.rstrip("/")
url = _urljoin(base, url)Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Fixes PipelineClientBase.format_url so a base URL’s trailing slash is preserved when the provided URL template is query-string-only (e.g. ?key=value), preventing incorrect path truncation before the ?.
Changes:
- Removed unconditional trailing-slash stripping from base URL formatting in
format_url. - Added a regression test covering query-string-only templates with a trailing-slash base URL.
- Documented the fix in the unreleased changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sdk/core/azure-core/azure/core/pipeline/transport/_base.py | Stops stripping trailing slash from the formatted base URL, enabling correct join behavior for query-only templates. |
| sdk/core/azure-core/tests/test_pipeline.py | Adds a regression test to ensure trailing slashes are preserved for query-only URL templates. |
| sdk/core/azure-core/CHANGELOG.md | Notes the bug fix in the unreleased “Bugs Fixed” section. |
|
|
||
| def test_format_url_trailing_slash_preserved_with_query_only(): | ||
| # Test that trailing slash in base URL is preserved when url_template is query-string only | ||
| # https://github.com/Azure/azure-sdk-for-python/issues/XXXXX |
There was a problem hiding this comment.
The comment references a placeholder issue link (issues/XXXXX). Please replace it with the actual issue/PR number (per the PR description this appears to be #45365) or remove the link to avoid stale placeholders in the test suite.
| # https://github.com/Azure/azure-sdk-for-python/issues/XXXXX | |
| # https://github.com/Azure/azure-sdk-for-python/issues/45365 |
|
|
||
| ### Bugs Fixed | ||
|
|
||
| - Fixed `PipelineClient.format_url` to preserve trailing slash in the base URL when the URL template is a query-string only (e.g. `?key=value`). #40426 |
There was a problem hiding this comment.
This changelog entry appears to reference a different issue number than the PR description (which mentions #45365). Please update the trailing reference to the correct issue/PR. Also consider tweaking the wording to be grammatically consistent with the PR title (e.g., 'query-string-only').
| - Fixed `PipelineClient.format_url` to preserve trailing slash in the base URL when the URL template is a query-string only (e.g. `?key=value`). #40426 | |
| - Fixed `PipelineClient.format_url` to preserve trailing slash in the base URL when the URL template is query-string-only (e.g., `?key=value`). #45365 |

When
format_urlis called with a query-string-only template (e.g.?key=value) and the base URL (resolved frompath_format_arguments) has a trailing slash, the trailing slash is incorrectly stripped.Changes
_base.py: Removed the unconditional.rstrip("/")from the base URL computation informat_url. This was always redundant for path stubs —_urljoinalready strips the trailing slash from the base path inside itsif stub_url_path:branch when actually joining path segments. For query-string-only stubs wherestub_url_pathis empty,_urljoinleaves the base path untouched, so the trailing slash is now correctly preserved before the?.test_pipeline.py: Added test covering the exact scenario from the issue.CHANGELOG.md: Updated unreleased section.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.