From 94d14e3d3706b7919babd6d07ad56849895eaa07 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 30 Mar 2026 16:11:06 -0700 Subject: [PATCH] Warning note about VACUUM and RenameTableEvent I noticed that VACUUM can update the rootpage for tables in a way that could confuse our rename table detection logic - but using the execute_isolated_fn() method to run VACUUM avoids this problem. Refs #2681 --- docs/internals.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/internals.rst b/docs/internals.rst index 3b65d57a..367ec223 100644 --- a/docs/internals.rst +++ b/docs/internals.rst @@ -1788,6 +1788,8 @@ The :ref:`prepare_connection() ` plugin hook is This allows plugins to execute database operations that might conflict with how database connections are usually configured. For example, running a ``VACUUM`` operation while bypassing any restrictions placed by the `datasette-sqlite-authorizer `__ plugin. +Running ``VACUUM`` using this method also ensures it won't trigger incorrect :class:`~datasette.events.RenameTableEvent` events, since ``execute_isolated_fn()`` does not trigger the Datasette mechanism that detects renamed tables in a way that can be confused by a ``VACUUM``. + Plugins can also use this method to load potentially dangerous SQLite extensions, use them to perform an operation and then have them safely unloaded at the end of the call, without risk of exposing them to other connections. Functions run using ``execute_isolated_fn()`` share the same queue as ``execute_write_fn()``, which guarantees that no writes can be executed at the same time as the isolated function is executing.