Store: a revoked or wrong token is retried six times per document instead of retiring the connection #13
Labels
No labels
bug
documentation
enhancement
performance
security
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Postulo/postulo-paperless#13
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found on 2026-09-29 in a read-only review of postulo-paperless at
973969bb7, reading how the store reports each answer Paperless can give and comparing it with what the core does with a store's exceptions.The core lets a store say that the other side has finished with a connection: it raises
ConnectionUnusable, andsend_copyswitches the connection off with the reason and stops dialling. This plugin never raises it. A 401 from Paperless is turned into an ordinaryPaperlessError, so a dead token is tried again for every document, six times each, and nothing tells the person until they notice the failed badges.src/postulo_paperless/store.py:116-126(Archive._get,Archive._post),:149-157(Archive.post_document) and:207-213(Archive.set_custom_field) raisePaperlessError(_explain(response))for every status that is not a success, 401 included. The import list at:36-44has noConnectionUnusable. In the core,documents/archiving.py:140-150catchesConnectionUnusableand callsconnection.retire(...);documents/archiving.py:151-153records anything else as a failure to retry;plugins/base.py:551-567names "a token the provider revoked" as the case the exception is for.put(archive.ensure("document_types", ...),store.py:319) answers 401. Each document's copy is recorded as failed: PaperlessError: HTTP 401: Invalid token. and retried after 5, 10, 20, 40 and 80 minutes, then gives up atMAX_ATTEMPTS. The connection stays switched on, shows no error of its own, and is dialled again for every new document. Once the token is corrected, the copies that used their six attempts are not picked up again:pending_copiesfilters onattempts__lt=MAX_ATTEMPTS, and Send everything leaves existing copies as they are, so each document has to be re-sent by hand with Send to stores now.documents/archiving.py:179-184).Archive, raiseConnectionUnusablewith a translated sentence when Paperless answers 401, from one helper used by_get,_post,post_documentandset_custom_field. Leave 403 as aPaperlessError: it means the token's account lacks one permission (creating a document type, say), which is fixed in Paperless and worth retrying. Decidekeep_secrets: the default forgets the token, which suits a revoked one.PaperlessStore.test()must go on answering with aTestResult, so add the new exception to what it catches atstore.py:304. AddConnectionUnusableto the namestests/test_surface.pychecks on the surface.Related to postulo/postulo#243 (closed), which made the core honour
ConnectionUnusablefor stores and records that #2 "stopped short of raising it" because the core did not act on it then. The core this repository pins (1d6cdd7e0) already does; the plugin's half was not done.Done when
tests/test_paperless.pyshows thatPaperlessStore().put(...)with a wrong token raisesConnectionUnusable, and thattest()with the same token still returns aTestResultthat is not ok.tests/test_paperless.py, throughsend_pending(), shows that a 401 leaves the connection switched off with the reason inlast_error, and that a second pending copy on the same connection is not attempted.Fixed by pull request #18.