Skip to content

Commit

Permalink
Stop using .raw_args, deprecate and undocument it - refs #706
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed May 27, 2020
1 parent 6d7cb02 commit 50652f4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions datasette/utils/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def args(self):

@property
def raw_args(self):
# Deprecated, undocumented - may be removed in Datasette 1.0
return {key: value[0] for key, value in self.args.items()}

async def post_vars(self):
Expand Down
4 changes: 2 additions & 2 deletions datasette/views/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def data(self, request, database, hash, default_labels=False, _size=None):
if request.args.get("sql"):
if not self.ds.config("allow_sql"):
raise DatasetteError("sql= is not allowed", status=400)
sql = request.raw_args.pop("sql")
sql = request.args.get("sql")
validate_sql_select(sql)
return await QueryView(self.ds).data(
request, database, hash, sql, _size=_size, metadata=metadata
Expand Down Expand Up @@ -107,7 +107,7 @@ async def data(
metadata=None,
_size=None,
):
params = request.raw_args
params = {key: request.args.get(key) for key in request.args}
if "sql" in params:
params.pop("sql")
if "_shape" in params:
Expand Down
8 changes: 4 additions & 4 deletions datasette/views/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ async def data(

extra_args = {}
# Handle ?_size=500
page_size = _size or request.raw_args.get("_size")
page_size = _size or request.args.get("_size")
if page_size:
if page_size == "max":
page_size = self.ds.max_returned_rows
Expand Down Expand Up @@ -558,8 +558,8 @@ async def data(
sql_no_limit=sql_no_limit.rstrip(), limit=page_size + 1, offset=offset
)

if request.raw_args.get("_timelimit"):
extra_args["custom_time_limit"] = int(request.raw_args["_timelimit"])
if request.args.get("_timelimit"):
extra_args["custom_time_limit"] = int(request.args["_timelimit"])

results = await db.execute(sql, params, truncate=True, **extra_args)

Expand Down Expand Up @@ -890,7 +890,7 @@ async def template_data():
"units": self.ds.table_metadata(database, table).get("units", {}),
}

if "foreign_key_tables" in (request.raw_args.get("_extras") or "").split(","):
if "foreign_key_tables" in (request.args.get("_extras") or "").split(","):
data["foreign_key_tables"] = await self.foreign_key_tables(
database, table, pk_values
)
Expand Down
3 changes: 0 additions & 3 deletions docs/internals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,6 @@ The request object is passed to various plugin hooks. It represents an incoming
``.args`` - RequestParameters
An object representing the parsed querystring parameters, see below.

``.raw_args`` - dictionary
A dictionary mapping querystring keys to values. If multiple keys of the same kind are provided, e.g. ``?foo=1&foo=2``, only the first value will be present in this dictionary.

The object also has one awaitable method:

``await request.post_vars()`` - dictionary
Expand Down

0 comments on commit 50652f4

Please # to comment.