Async support for magic parameters

Closes #2441
This commit is contained in:
Simon Willison 2024-11-15 13:17:45 -08:00
commit dce718961c
4 changed files with 38 additions and 4 deletions

View file

@ -360,9 +360,13 @@ def register_magic_parameters():
else:
raise KeyError
async def asyncrequest(key, request):
return key
return [
("request", request),
("uuid", uuid),
("asyncrequest", asyncrequest),
]

View file

@ -857,6 +857,9 @@ def test_hook_register_magic_parameters(restore_working_directory):
"get_uuid": {
"sql": "select :_uuid_new",
},
"asyncrequest": {
"sql": "select :_asyncrequest_key",
},
}
}
}
@ -871,6 +874,10 @@ def test_hook_register_magic_parameters(restore_working_directory):
assert 200 == response_get.status
new_uuid = response_get.json[0][":_uuid_new"]
assert 4 == new_uuid.count("-")
# And test the async one
response_async = client.get("/data/asyncrequest.json?_shape=array")
assert 200 == response_async.status
assert response_async.json[0][":_asyncrequest_key"] == "key"
def test_hook_forbidden(restore_working_directory):