From e82bf89fa5d493eb9f64dbac7704a28104d411a1 Mon Sep 17 00:00:00 2001 From: Sebastian Cao Date: Sun, 2 Aug 2026 11:41:09 +0800 Subject: [PATCH] Mention that filters_from_request can return an async function --- docs/plugin_hooks.rst | 2 ++ tests/test_docs.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/docs/plugin_hooks.rst b/docs/plugin_hooks.rst index 049cb292..e87ac8a4 100644 --- a/docs/plugin_hooks.rst +++ b/docs/plugin_hooks.rst @@ -1419,6 +1419,8 @@ The arguments to the ``FilterArguments`` class constructor are as follows: ``extra_context`` - dictionary, optional Additional context variables that should be made available to the ``table.html`` template when it is rendered. +The hook can also return an ``async def`` function, which Datasette will await. This is useful if you need to execute SQL queries or perform other asynchronous operations in order to build your filters. Datasette's own default implementations of this hook `use this pattern `__. + This example plugin causes 0 results to be returned if ``?_nothing=1`` is added to the URL: .. code-block:: python diff --git a/tests/test_docs.py b/tests/test_docs.py index 16df6a46..596673f0 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -59,6 +59,13 @@ def test_plugin_hooks_are_documented(plugin_hooks_content, subtests): ), f"Missing from plugin hook documentation: {expected}" +def test_filters_from_request_async_function_documented(plugin_hooks_content): + section = plugin_hooks_content.split(".. _plugin_hook_filters_from_request:")[ + -1 + ].split(".. _plugin_hook_")[0] + assert "async def" in section + + @pytest.fixture(scope="session") def documented_views(): view_labels = set()