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

keep_blank_values=True when parsing request.args #1551

Closed
simonw opened this issue Dec 12, 2021 · 3 comments
Closed

keep_blank_values=True when parsing request.args #1551

simonw opened this issue Dec 12, 2021 · 3 comments

Comments

@simonw
Copy link
Owner

simonw commented Dec 12, 2021

This code in TableView wouldn't be necessary:

# Ensure we don't drop anything with an empty value e.g. ?name__exact=
args = MultiParams(
urllib.parse.parse_qs(request.query_string, keep_blank_values=True)
)

If that happened here instead:

@property
def args(self):
return MultiParams(parse_qs(qs=self.query_string))

Originally posted by @simonw in #1518 (comment)

@simonw
Copy link
Owner Author

simonw commented Dec 12, 2021

This is technically a backwards-incompatible for any plugins that use request.args - but it's unlikely to break anything. At any rate this needs to happen before Datasette 1.0!

@simonw simonw added this to the Datasette 1.0 milestone Dec 12, 2021
@simonw
Copy link
Owner Author

simonw commented Dec 12, 2021

Python documentation for parse_qs: https://docs.python.org/3/library/urllib.parse.html#urllib.parse.parse_qs

The optional argument keep_blank_values is a flag indicating whether blank values in percent-encoded queries should be treated as blank strings. A true value indicates that blanks should be retained as blank strings. The default false value indicates that blank values are to be ignored and treated as if they were not included.

@simonw
Copy link
Owner Author

simonw commented Dec 12, 2021

Here's an example of the difference that causes:

>>> import urllib.parse
>>> urllib.parse.parse_qs("foo=bar")
{'foo': ['bar']}
>>> urllib.parse.parse_qs("foo=bar&baz=")
{'foo': ['bar']}
>>> urllib.parse.parse_qs("foo=bar&baz=", keep_blank_values=True)
{'foo': ['bar'], 'baz': ['']}

@simonw simonw closed this as completed in a6ff123 Dec 12, 2021
simonw added a commit that referenced this issue Dec 17, 2021
@simonw simonw modified the milestones: Datasette 1.0, Datasette 0.60 Jan 13, 2022
simonw added a commit that referenced this issue Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant