Skip to content

Commit

Permalink
Use execute_isolated_fn() if available, closes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Feb 9, 2024
1 parent 85bcdb4 commit e510ce3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion datasette_edit_schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,13 @@ def do_drop_table(conn):
db[table].drop()
db.vacuum()

await datasette.databases[database.name].execute_write_fn(do_drop_table, block=True)
if hasattr(database, "execute_isolated_fn"):
await database.execute_isolated_fn(do_drop_table)
# For the tests
datasette._datasette_edit_schema_used_execute_isolated_fn = True
else:
await database.execute_write_fn(do_drop_table)

datasette.add_message(request, "Table has been deleted")
await track_event(
datasette,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_edit_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ async def test_drop_table(permission_plugin, db_path, actor_id, should_allow):
event = get_last_event(ds)
if event is not None:
assert event.name == "drop-table"
# This should have used isolated_fn as well:
assert getattr(ds, "_datasette_edit_schema_used_execute_isolated_fn", None)
else:
assert response.status_code == 403
assert "creatures" in db.table_names()
Expand Down

0 comments on commit e510ce3

Please sign in to comment.