OperationalError: database table is locked fix

See also:
- https://til.simonwillison.net/datasette/remember-to-commit
pull/2173/head
Simon Willison 2023-08-31 10:46:07 -07:00 zatwierdzone przez GitHub
rodzic 4c3ef03311
commit 9cead33fb9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 3 dodań i 0 usunięć

Wyświetl plik

@ -1012,6 +1012,7 @@ For example:
def delete_and_return_count(conn):
conn.execute("delete from some_table where id > 5")
conn.commit()
return conn.execute(
"select count(*) from some_table"
).fetchone()[0]
@ -1028,6 +1029,8 @@ The value returned from ``await database.execute_write_fn(...)`` will be the ret
If your function raises an exception that exception will be propagated up to the ``await`` line.
If you see ``OperationalError: database table is locked`` errors you should check that you remembered to explicitly call ``conn.commit()`` in your write function.
If you specify ``block=False`` the method becomes fire-and-forget, queueing your function to be executed and then allowing your code after the call to ``.execute_write_fn()`` to continue running while the underlying thread waits for an opportunity to run your function. A UUID representing the queued task will be returned. Any exceptions in your code will be silently swallowed.
.. _database_close: