Skip to content

Commit cbb77b5

Browse files
artcgahopkins
andauthored
fix issue where request.args.pop removed parameters inconsistently (#2112)
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
1 parent 35c7625 commit cbb77b5

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

sanic/request.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,12 @@ def get_args(
265265
:type errors: str
266266
:return: RequestParameters
267267
"""
268-
if not self.parsed_args[
269-
(keep_blank_values, strict_parsing, encoding, errors)
270-
]:
268+
if (
269+
keep_blank_values,
270+
strict_parsing,
271+
encoding,
272+
errors,
273+
) not in self.parsed_args:
271274
if self.query_string:
272275
self.parsed_args[
273276
(keep_blank_values, strict_parsing, encoding, errors)
@@ -321,9 +324,12 @@ def get_query_args(
321324
:type errors: str
322325
:return: list
323326
"""
324-
if not self.parsed_not_grouped_args[
325-
(keep_blank_values, strict_parsing, encoding, errors)
326-
]:
327+
if (
328+
keep_blank_values,
329+
strict_parsing,
330+
encoding,
331+
errors,
332+
) not in self.parsed_not_grouped_args:
327333
if self.query_string:
328334
self.parsed_not_grouped_args[
329335
(keep_blank_values, strict_parsing, encoding, errors)

tests/test_requests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ async def handler(request):
289289
assert request.args.getlist("test1") == ["1"]
290290
assert request.args.get("test3", default="My value") == "My value"
291291

292+
def test_popped_stays_popped(app):
293+
@app.route("/")
294+
async def handler(request):
295+
return text("OK")
296+
297+
request, response = app.test_client.get(
298+
"/", params=[("test1", "1")]
299+
)
300+
301+
assert request.args.pop("test1") == ["1"]
302+
assert "test1" not in request.args
292303

293304
@pytest.mark.asyncio
294305
async def test_query_string_asgi(app):

0 commit comments

Comments
 (0)