wrolpi/modules/docs/test
Roland 9310fe801f
Make doc_modeler resilient to SQLite "database is locked"
A refresh on a large library aborted the whole doc_modeler run on the
first lock error, so the ~20k stranded docs never got modeled.

doc_modeler held one write transaction across a whole batch of 10 docs
while doing slow per-doc extraction (a PDF/epub can be tens of MB). When
another connection committed mid-batch, the deferred transaction failed
to upgrade to a write with SQLITE_BUSY_SNAPSHOT ("database is locked",
which busy_timeout does not absorb -- the same trap that motivated the
short-transaction rewrite of apply_indexers). The per-item error handler
then did `logger.error(f'... {file_group}')`, which lazy-loaded an
attribute on the now-rolled-back session and raised a *second* exception,
escaping the handler and aborting the entire modeler.

Restructure:
- Pick each batch of candidate ids in a short read-only transaction, then
  model each doc in its own short write transaction. A lock/error on one
  doc rolls back only that doc and cannot poison the rest of the run.
- Retry a doc a few times on "database is locked" -- a fresh transaction
  gets a fresh snapshot and succeeds.
- Log the plain file_group id on failure; never touch the ORM object on a
  possibly rolled-back session.
- Track only *failed* ids for the termination guard (successes are
  excluded by the Doc.id IS NULL gate), keeping the notin_ set small and
  well under SQLite's bound-variable limit.

Adds test_doc_modeler_survives_database_locked.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-20 13:44:27 -06:00
..
__init__.py Add Docs module for searching and organizing PDFs and EPUBs 2026-03-20 14:17:06 -06:00
test_api.py Consolidating deletion endpoints. 2026-05-03 19:14:30 -06:00
test_doc_modeler.py Make doc_modeler resilient to SQLite "database is locked" 2026-07-20 13:44:27 -06:00
test_extractors.py Adding simple search to epub viewer. 2026-04-13 17:23:20 -06:00
test_lib.py Search: fast ABC mode by default, opt-in deep search 2026-07-03 10:32:16 -06:00
test_models.py Add Docs module for searching and organizing PDFs and EPUBs 2026-03-20 14:17:06 -06:00