Commit graph

12 commits

Author SHA1 Message Date
August Cayzer
a759c47c9e Return MultiParams from request.post_vars() to preserve multi-valued form fields
Form submissions with multiple values for the same key (e.g. ``<select
multiple>``) previously had every value but the last silently discarded,
because ``post_vars()`` called ``dict(parse_qsl(...))``. Switch the
implementation to return a ``MultiParams`` object built from
``parse_qs(...)``, mirroring the existing ``request.args`` shape so both
sides of the GET/POST surface behave consistently.

``MultiParams`` gains an ``items()`` method that yields (key, first_value)
pairs, matching ``__getitem__`` semantics, so it works in patterns such as
``dict(post_vars())`` and the existing ``_coerce_execute_write_payload``
dict comprehension.

Internal callers of ``_json_or_form_payload`` (``execute_write`` and
``stored_queries``) had ``isinstance(data, dict)`` guards intended to
validate JSON shape but also rejected the new ``MultiParams`` return on
the form path. Gate those guards on ``is_json`` so the form path passes
through unchanged.

The bundled ``my_plugin`` test fixture wraps ``post_vars()`` in ``dict()``
before passing to ``Response.json``, demonstrating the migration path for
plugins that need a JSON-serialisable mapping.

Closes #2425
2026-05-29 21:43:39 +01:00
Simon Willison
5c5e9b3657 Request.fake(... url_vars), plus .fake() is now documented
Also made 'from datasette import Request' shortcut work.

Closes #1697
2022-03-31 19:01:58 -07:00
Simon Willison
4f02c8d4d7 Test for JSON in query_string name, refs #621
Plus simplified implementation of test_request_blank_values
2021-12-14 12:29:05 -08:00
Simon Willison
a6ff123de5 keep_blank_values=True when parsing query_string, closes #1551
Refs #1518
2021-12-12 12:01:51 -08:00
Simon Willison
ff0dd4da38 repr() method for Request, refs #1519 2021-11-19 12:29:37 -08:00
Simon Willison
b267b57754
Upgrade to httpx 0.20
* Upgrade to httpx 0.20, closes #1488
* TestClient.post() should not default to following redirects
2021-10-14 11:03:44 -07:00
Simon Willison
8e8fc5cee5 Applied Black 2021-01-11 13:34:38 -08:00
Simon Willison
649f48cd70 request.full_path property, closes #1184 2021-01-11 13:32:58 -08:00
Simon Willison
1f6a134369 await request.post_body() method, closes #897 2020-07-17 13:12:35 -07:00
Simon Willison
fac8e93815 request.url_vars property, closes #822 2020-06-08 20:40:00 -07:00
Simon Willison
0934844c0b request.post_vars() no longer discards empty values 2020-06-03 06:48:39 -07:00
Simon Willison
de1cde65a6 Moved request tests to test_internals_request.py 2020-05-30 10:45:11 -07:00