datasette/datasette
Simon Willison 1289eb0589 Fix SQLite locking issue in execute_write_script
The execute_write_script() method was causing SQLite database locking
errors when multiple executescript() calls ran in quick succession.

Root cause: SQLite's executescript() method has special behavior - it
implicitly commits any pending transaction and operates in autocommit
mode. However, execute_write_script() was passing these calls through
execute_write_fn() with the default transaction=True, which wrapped
the executescript() call in a transaction context (with conn:).

This created a conflict where sequential executescript() calls would
cause the second call to fail with "OperationalError: database table
is locked: sqlite_master" because the sqlite_master table was still
locked from the first operation's implicit commit.

Fix: Pass transaction=False to execute_write_fn() since executescript()
manages its own transactions and should not be wrapped in an additional
transaction context.

This was causing test_hook_extra_body_script to fail because the
internal database initialization (which calls executescript twice in
succession) would fail, preventing the application from rendering
pages correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 10:30:09 -07:00
..
publish Use service-specific image ID for Cloud Run deploys, refs #2036 2023-03-08 12:25:55 -08:00
static Ran prettier 2025-10-25 15:38:07 -07:00
templates Better display of recent permissions checks, refs #2543 2025-10-30 10:28:04 -07:00
utils Fix type annotation bugs and remove unused imports 2025-10-26 16:03:13 -07:00
views Simplified the code for the permission debug pages 2025-10-30 10:28:04 -07:00
__init__.py track_event() mechanism for analytics and plugins 2024-01-31 15:21:40 -08:00
__main__.py Add support for running datasette as a module (#556) 2019-07-11 09:07:44 -07:00
actor_auth_cookie.py Remove python-baseconv dependency, refs #1733, closes #1734 2022-05-02 12:39:06 -07:00
app.py Improved permissions UI WIP 2025-10-30 10:28:04 -07:00
blob_renderer.py Rename route match groups for consistency, refs #1667, #1660 2022-03-19 09:52:08 -07:00
cli.py Fix type annotation bugs and remove unused imports 2025-10-26 16:03:13 -07:00
database.py Fix SQLite locking issue in execute_write_script 2025-10-30 10:30:09 -07:00
default_actions.py Fix view-database-download permission handling 2025-10-25 15:38:07 -07:00
default_magic_parameters.py Fix datetime.utcnow deprecation warning 2024-03-15 15:32:12 -07:00
default_menu_links.py Update permission hooks to include source_plugin column and simplify menu_links 2025-10-25 15:38:07 -07:00
default_permissions.py Fix type annotation bugs and remove unused imports 2025-10-26 16:03:13 -07:00
events.py Fix type annotation bugs and remove unused imports 2025-10-26 16:03:13 -07:00
facets.py Fix huge performance bug in DateFacet, refs #2407 2024-08-21 14:38:11 -07:00
filters.py Fix type annotation bugs and remove unused imports 2025-10-26 16:03:13 -07:00
forbidden.py Fixed a bunch of unused imports spotted with ruff 2024-02-06 17:27:20 -08:00
handle_exception.py debugger: load 'ipdb' if present 2024-08-20 20:02:35 -07:00
hookspecs.py Remove permission_allowed hook entirely, refs #2528 2025-10-25 15:38:07 -07:00
inspect.py Modernize code to Python 3.6+ (#1158) 2020-12-23 09:04:32 -08:00
permissions.py Fix type annotation bugs and remove unused imports 2025-10-26 16:03:13 -07:00
plugins.py Fix type annotation bugs and remove unused imports 2025-10-26 16:03:13 -07:00
renderer.py Fix type annotation bugs and remove unused imports 2025-10-26 16:03:13 -07:00
resources.py Migrate view-query permission to SQL-based system, refs #2510 2025-10-25 15:38:07 -07:00
sql_functions.py _search= queries now correctly escaped, fixes #651 2019-12-29 18:48:30 +00:00
tracer.py Tracer now catches errors, closes #2405 2024-08-21 12:19:18 -07:00
url_builder.py count all rows button on table page, refs #2408 2024-08-21 19:09:25 -07:00
version.py Release 1.0a19 2025-04-21 22:38:53 -07:00