Skip to content

Merge params with existing URL query parameters instead of replacing#3761

Open
veeceey wants to merge 1 commit intoencode:masterfrom
veeceey:fix/issue-3621
Open

Merge params with existing URL query parameters instead of replacing#3761
veeceey wants to merge 1 commit intoencode:masterfrom
veeceey:fix/issue-3621

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 8, 2026

Summary

  • Fixes When the URL contains request parameters and the params parameter is set, the request parameters in the URL will disappear unexpectedly. #3621: When a URL already contains query parameters (e.g. https://example.com/path?page=1&s=list) and the params argument is also provided, the existing query parameters were silently dropped and replaced by only the new params. This was inconsistent with the requests library and surprised users.
  • Changed Request.__init__ to use URL(url).copy_merge_params(params) instead of URL(url, params=params), so existing URL query parameters are preserved and merged with the new ones.
  • Updated test_request_params to reflect the new merge behavior and added an additional test case for overlapping keys.

Before (broken)

request = httpx.Request("GET", "https://example.com?page=1&s=list", params={"pid": 0})
print(request.url)
# https://example.com?pid=0   <-- page and s are lost!

After (fixed)

request = httpx.Request("GET", "https://example.com?page=1&s=list", params={"pid": 0})
print(request.url)
# https://example.com?page=1&s=list&pid=0   <-- all params preserved

Test plan

  • Existing test_request_params updated and passes
  • New test case for overlapping parameter keys added
  • All 173 model and client tests pass
  • Verified the exact reproduction case from the issue works correctly

🤖 Generated with Claude Code

…them

When a URL already contains query parameters and the `params` argument is
also provided, the existing query parameters are now merged with the new
ones instead of being silently dropped. This aligns with the behavior of
the `requests` library and matches user expectations.

Fixes encode#3621

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

When the URL contains request parameters and the params parameter is set, the request parameters in the URL will disappear unexpectedly.

1 participant