Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(20.12 LTS backport) fix request.args.pop removing parameters inconsistently #2112

Merged
merged 2 commits into from Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions sanic/request.py
Expand Up @@ -265,9 +265,12 @@ def get_args(
:type errors: str
:return: RequestParameters
"""
if not self.parsed_args[
(keep_blank_values, strict_parsing, encoding, errors)
]:
if (
keep_blank_values,
strict_parsing,
encoding,
errors,
) not in self.parsed_args:
if self.query_string:
self.parsed_args[
(keep_blank_values, strict_parsing, encoding, errors)
Expand Down Expand Up @@ -321,9 +324,12 @@ def get_query_args(
:type errors: str
:return: list
"""
if not self.parsed_not_grouped_args[
(keep_blank_values, strict_parsing, encoding, errors)
]:
if (
keep_blank_values,
strict_parsing,
encoding,
errors,
) not in self.parsed_not_grouped_args:
if self.query_string:
self.parsed_not_grouped_args[
(keep_blank_values, strict_parsing, encoding, errors)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_requests.py
Expand Up @@ -289,6 +289,17 @@ async def handler(request):
assert request.args.getlist("test1") == ["1"]
assert request.args.get("test3", default="My value") == "My value"

def test_popped_stays_popped(app):
@app.route("/")
async def handler(request):
return text("OK")

request, response = app.test_client.get(
"/", params=[("test1", "1")]
)

assert request.args.pop("test1") == ["1"]
assert "test1" not in request.args

@pytest.mark.asyncio
async def test_query_string_asgi(app):
Expand Down