Zum Inhalt

In per-user ownership, follow every upload until its document has its owner, and prove a lost upload by the ID of its document

  • Status: accepted
  • Date: 2026-11-23
  • Amends 0025: the documents of the account wait while an upload may still create its document, which a record of the upload follows, not while the state of its file waits for its task
  • Amends 0568: a document of the account counts as the user's own lost upload by its ID, higher than every document of that content before the first upload, not by the time when Paperless added it

Context

In per-user ownership, Paperless makes the account of the app the owner of every upload, and the app gives the document the owner of its file once the task of the upload names it (0025). Until then the document looks like any other document of the account, which goes to the target user, so the runs held the documents of the account while the state of an upload waited for its task. Nothing in Paperless-ngx ties a task to the client that uploaded its file: PostDocumentView queues the file with the account as its owner and answers with the ID of the task, and the consumer creates the document whenever its worker gets to the task, also after the client stopped asking (read in the code of v2.20.15 and v3.5.1, not run).

The state of a file stops waiting in several ordinary ends while Paperless may still create the document: the file leaves the inbox, or changes, before its task ends; the answer of the upload never comes, so the state waits for its next attempt; a send gives up after its last attempt; Paperless lists the task unfinished a day after the upload, so the file moves to the error folder, or a send ends; and an administrator turns the inbox off. In each of them the document reached the archive of the target user once Paperless created it.

0568 proved a lost upload by the time of its first attempt, which only the next attempt of the same file used, and which rested on the clocks of Nextcloud and Paperless: a Paperless whose clock runs behind showed the document as older than its upload. Its sentence that the file "then goes up again as in option 1" holds for Paperless-ngx 3.x, which imports a second document, while the first stays with the account; Paperless-ngx 2.x refuses the file as a duplicate, so it ended in the error folder, and the document stayed with the account too.

Options

  1. Keep the states as they are, and hold longer. The states end for good reasons, and a state that outlives its file, or a send that never ends, would change the inbox and Send to Paperless for users.
  2. A record of each upload, from right before it until its document has its owner, apart from the states. It costs a table and, in each scheduled run, a question for each record: for its task, or a search by its content.
  3. A mark that Paperless keeps, such as a custom field with an opaque ID of the upload. It would tell the upload's document apart from the first second. But Paperless-ngx 2.16, the oldest version that the app supports, takes the custom fields of an upload as a list of IDs without values (PostDocumentSerializer), the field must exist, so the account needs the permission to add custom fields, users see the field and can change it, and the sidecars and the export would have to leave it out. The task list is no mark either: 2.x doesn't filter /api/tasks/ by owner, and task_file_name repeats when a scanner names every scan the same.

For the proof of a lost upload:

  • The Date of an answer of Paperless as the first time: the answer of the upload has none when it is lost, and the Date of the search before it is often that of a proxy, which nginx doesn't take from the server that it proxies unless told to.
  • The ID of the document: the search before the upload already asks for the documents with the content, and asks for the highest ID first (ordering=-id, which DocumentViewSet.ordering_fields of Paperless-ngx names); a document of the account with a higher ID came after that search.

Decision

Option 2, with the proof by the ID.

  • The record. In per-user ownership, right before each upload of the inbox and of Send to Paperless, the app saves a record of it, for a user whose user of Paperless is another than the account: the user, the source, the path of the file, the SHA-256 and the MD5 of the content, the highest ID of a document with that content from the search before the first upload (0 for none), the time of the last attempt and, once Paperless names it, the task. A user has one record for each content: a further attempt takes it over and keeps its first ID and its start. Single ownership, a user without a user of Paperless and the user of the account save none, as their documents stay with the account anyway; a refusal of Paperless ends the record that its upload started.
  • The hold. The documents of the account wait while a record is open: while its task may still create its document, up to 30 days after the upload, and without a task, after an answer that never came, for a day after its last attempt. The states of the files that wait for their tasks hold as before. The run of one document, the webhook, leaves a document of the account to the scheduled runs while any record has not ended.
  • The settling. Each scheduled run settles the records after it has read the documents and before it routes them: the document of a task that ended gets its owner, and while Paperless refuses the owner for a reason that may pass, the record waits for it, as long as it follows its upload, since such a document may appear long after its upload, while a refusal for good, such as 403, ends the record, and the document keeps the owner that Paperless gave it, as for the inbox; a task that ended without a document ends the record; a record without a task, or whose task Paperless no longer lists or names no document, looks for the document of its content with a higher ID than its own, confirms a match by the MD5 alone with its original, as 0564 does, and gives it its owner. The document reaches its user in the same run, and the user's report and Activity name it. A record ends when its document has its owner, and 30 days after its upload, which the report names. Nothing is deleted, and a file in the error folder stays there.
  • The proof. A document of the account counts as the user's own lost upload when its ID is higher than the one that the user's record of that content keeps, also for a file of the same content, such as one moved back from the error folder: the comparison of the time when Paperless added it goes. A file without a record has no proof, and goes up.
  • After an answer that never came. While a record without a task holds, for a day after its last attempt, its content doesn't go up again: the file of the inbox waits for its next attempt, and a sent file waits without using up its attempts. A second upload in that time could fail as a duplicate of the first upload's document on Paperless-ngx 2.x, which would end the record, or create a second document on 3.x, which the search, as it names the newest, would take for the upload's; either way the first document would stay with the account. After the day, the upload that goes again leaves the record to its content instead of its new task, so that a document that the first upload still creates gets its owner, also when Paperless refuses the new upload as its duplicate.
  • Two records, one document. A document that the records of two users find by its content gets neither owner, and the reports of both name it, until someone in Paperless gives it its owner, which ends both records and holds nothing more; a record never takes a document that the task of another record names. A search or a task that Paperless can't answer keeps the record and holds every document of the account in that run.

The two times are named constants of UploadRecords. The day is ImportPlanner::TASK_TIMEOUT, the time that the app already gives Paperless to finish a task: an upload whose answer never came has its document by then, unless its task waits in a long queue, which the look of each run still finds. The 30 days cover a worker of Paperless that stopped over the holidays, or a queue that many large uploads filled, and end the record so that nothing waits for good.

The numbers of Paperless

The proof assumes that Paperless numbers its documents in ascending order and gives no number twice. Paperless-ngx keeps the ID of a document in the automatic primary key of Django, read in the documentation of each database, not run:

  • PostgreSQL takes the next value of a sequence, which never hands out a value twice, also after a rollback or a deleted row, unless someone resets it.
  • SQLite: Django creates the key with AUTOINCREMENT, which keeps the highest ID ever used in sqlite_sequence and never takes a deleted one again.
  • MariaDB and MySQL: InnoDB kept its counter only in memory before MySQL 8.0 and MariaDB 10.2.4, and after a restart started again after the highest row, so the ID of a deleted highest row could come again. Both persist the counter since, and the Django of Paperless-ngx 2.x and 3.x needs MySQL 8.0.11 and MariaDB 10.4 at least.

Paperless keeps a deleted document in its trash with its ID, which the search before the upload doesn't see. A document of the account with the content of a file that someone restores from the trash while a record looks for its document counts as that upload's. On Paperless-ngx 2.x the upload of such a content ends as a duplicate of the document in the trash, so its task ends the record; on 3.x it stays a rest, which needs a restore by hand of a document of the same content within those 30 days.

Whether the tags that a user may see (0038) keep such a document from a restricted target user: no. A document whose owner's route allows none of its users goes to the target user as the last stop, so only a record that gives the document its owner keeps it from the target user.

Consequences

A document that an upload of a user may have created reaches that user, also after the file has left the inbox, after an answer that never came, after a send that gave up, when Paperless finishes the task more than a day late, with the inbox turned off, and whatever the clocks of Nextcloud and Paperless say. While a record is open, the documents of the account wait: those that someone gave to the account by hand, and the uploads of the target user without a user of Paperless, for a day after an answer that never came, and for up to 30 days while Paperless lists a task unfinished; the report says whose upload they wait for, and since when. Each record costs a scheduled run a question for its task while it has one, or else up to two searches, the SHA-256 first and then the MD5, with a read of the document that they find and at most one download of its original; single ownership asks nothing more.

The rest that 0568 accepted for two uploads of the same content, which neither got an answer for, narrows: such a document now gets neither owner. A watch of 30 days widens another one on Paperless-ngx 3.x: a document of the account with the content of the file and a higher ID may be an upload of the same file that has no record, such as one of the target user without a user of Paperless; it goes to the record's user, who uploaded the same bytes. An upload whose answer never came and whose task waits in the queue of Paperless for more than the day goes up again: on Paperless-ngx 3.x, which then keeps two documents of the content, the second gets its owner and the first, which the search no longer names, may reach the target user. Documents that Paperless splits by barcodes have other checksums, so a record that watches finds them by their task alone. A file that waited for its next attempt, or a task, at the update that brought the records has none, so its document is followed as before: the next attempt uploads it again, and a task that Paperless finishes after the state of its file has ended reaches the target user once.