requests
requests copied to clipboard
Fix: Ensure empty lists in params are encoded as empty keys #6557
Fixes #6557
Summary
Previously, passing an empty list as a query parameter value (e.g., params={'key': []}) caused the key to be silently dropped from the URL. This behavior was inconsistent with empty strings (params={'key': ''}), which correctly produce ?key=.
Changes
- Modified parameter encoding logic in
models.pyto treat empty lists as a list containing a single empty string['']. - Verified that
?key=is generated, matching the behavior of empty strings.
Tests
- Added regression test
test_params_with_empty_list_are_includedintests/test_requests.py. - Verified locally with
pytest.