wrolpi/modules/zim
Roland 70ab0fcd5d
Tests fail when a request writes outside request.ctx.db.write()
A request's transaction begins deferred.  A write in it after a read fails
instantly ("database is locked") when another connection wrote in between,
and a write left for the response middleware's commit can be lost after the
response was sent.  #846-#853 and #863 moved handlers' writes into
request.ctx.db.write(); this keeps it that way.

Under pytest, a listener records every INSERT/UPDATE/DELETE/REPLACE made
while a request runs (or in a task it started) outside RequestDB.write()
or get_db_session(commit=True), and the autouse no_deferred_request_writes
fixture fails the test.  allow_deferred_request_writes opts a test out.
The test-only response listener now runs switches outside the request,
as production's perpetual process does.

It found three more:
- DELETE /api/zim/<ids> deleted the .zim file, returned 204, then lost the
  row's delete when the middleware's commit failed under contention.  It
  now writes in request.ctx.db.write().
- Viewing a file recorded the view in a background task on the request's
  Session, after the request ended.  set_file_viewed opens its own write.
- tags.import_config (startup and config import) read, then wrote, in a
  deferred get_db_session().  It now begins as a writer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 14:51:55 -06:00
..
test Tests fail when a request writes outside request.ctx.db.write() 2026-10-23 14:51:55 -06:00
__init__.py Zim/Kiwix (Wikipedia) feature 2023-07-10 21:30:40 -06:00
api.py Tests fail when a request writes outside request.ctx.db.write() 2026-10-23 14:51:55 -06:00
conftest.py Using aria2c to download files. Removing custom file download functions. 2025-01-10 11:32:37 -07:00
downloader.py Migrating Kiwix downloaders. 2026-05-07 15:54:53 -06:00
errors.py Adding toggle to Channel page to stop downloading comments for certain channels. 2025-03-01 18:23:29 -07:00
kiwix.py Adding Khan Academy to zim subscriptions. Updating some kiwix catalog sizes. 2025-03-03 16:32:35 -07:00
lib.py db: serializers read only loaded data (#777) 2026-10-04 18:28:08 -06:00
models.py Model reprs read only loaded state (#819) 2026-10-11 16:47:32 -06:00
schema.py Adding feature which adds toggles to Zim files to enable/disable auto search. 2025-02-02 12:43:04 -07:00