Don't explain an explain even in the demo, refs #2293

pull/2295/head
Simon Willison 2024-03-05 18:14:55 -08:00
rodzic 5de6797d4a
commit 4d24bf6b34
3 zmienionych plików z 13 dodań i 8 usunięć

Wyświetl plik

@ -1557,7 +1557,10 @@ This example adds a new query action linking to a page for explaining a query:
@hookimpl
def query_actions(datasette, database, sql):
def query_actions(datasette, database, query_name, sql):
# Don't explain an explain
if sql.lower().startswith("explain"):
return
return [
{
"href": datasette.urls.database(database)
@ -1571,7 +1574,6 @@ This example adds a new query action linking to a page for explaining a query:
},
]
.. _plugin_hook_database_actions:
database_actions(datasette, actor, database, request)

Wyświetl plik

@ -393,11 +393,9 @@ def table_actions(datasette, database, table, actor):
@hookimpl
def query_actions(datasette, database, query_name, sql):
args = {
"sql": sql,
}
if query_name:
args["query_name"] = query_name
# Don't explain an explain
if sql.lower().startswith("explain"):
return
return [
{
"href": datasette.urls.database(database)

Wyświetl plik

@ -954,6 +954,8 @@ async def test_hook_table_actions(ds_client, table_or_view):
"/fixtures/pragma_cache_size",
"/fixtures?sql=explain+PRAGMA+cache_size%3B",
),
# Don't attempt to explain an explain
("/fixtures?sql=explain+select+1", None),
),
)
async def test_hook_query_actions(ds_client, path, expected_url):
@ -967,7 +969,10 @@ async def test_hook_query_actions(ds_client, path, expected_url):
response = await ds_client.get(path)
assert response.status_code == 200
links = get_table_actions_links(response.text)
assert links == [{"label": "Explain this query", "href": expected_url}]
if expected_url is None:
assert links == []
else:
assert links == [{"label": "Explain this query", "href": expected_url}]
@pytest.mark.asyncio