Commit Graph
12569 Commits
Author SHA1 Message Date
Trenton H 4d19cb8106 Fix: move files before the bulk update websocket notification 2026-11-26 14:42:37 -08:00
Trenton H 976920d6d1 Fix: flush file moves before the scheduled workflow websocket notification 2026-11-26 14:42:37 -08:00
Trenton H 0347ac7cae Fix: move documents when a tag is cleared through the reverse relation 2026-11-26 14:42:37 -08:00
Trenton H 6ddc6f74a7 Improves test coverage even for the exception cases 2026-11-26 14:42:37 -08:00
Trenton H cdbcf8c0b0 Fix: rename only root documents in document_renamer 2026-11-26 14:42:37 -08:00
Trenton H 5563277dcf Fix: move versions of trashed documents 2026-11-26 14:42:37 -08:00
Trenton H c87084206a Fix: move documents when tags change through the reverse relation 2026-11-26 14:42:37 -08:00
Trenton H 7db96d8b7a Fix: refresh the document after placing files, before the post-consume script 2026-11-26 14:42:37 -08:00
stumpylog 2d6819ecc7 Trimming and simpliciation 2026-11-26 14:42:37 -08:00
stumpylog 04e9cabbd5 Fix: return the post-move modified time from document updates
Editing a document in a way that renames its file returned a response carrying the modified time from before the move. The deferred file move runs after the response is built and bumps modified, so the stored value was newer than the one the client received. The frontend then saw a newer server modified time and showed a spurious "document was updated" prompt whose reload discarded local edits.

DocumentViewSet.update now flushes pending file moves right after saving and before reading the document back, so the response reflects the final filename and modified time.
2026-11-26 14:42:37 -08:00
stumpylog 04056505be Fix: skip the thread hop for async file move scopes with nothing to move
adefer_file_moves hopped to a worker thread on every exit, even when no file move had been requested, which costs an executor round trip for most async requests.

The collector is now closed on the event loop, which touches no database, and the flush only runs through sync_to_async when something was collected. The transaction check still happens inside the flush in the sync thread. The comment above the lock-free filename precheck in move_files_for_document now gives the real reason it uses values_list(): it keeps the check off Document.global_objects.filter(), which tests patch to inject database errors and observe the mover's writes.
2026-11-26 14:42:37 -08:00
stumpylog e9e8389544 Fix: place consumed files before running the post-consume script
The consumer's storage phase opens its own file move scope, which nests under the consume task's scope. Moves requested while storing the document therefore stayed pending until the task ended, and the post-consume script could be handed a path from before the move.

The consumer now flushes the pending file moves once after the storage block, outside the media lock and the transaction, and before the post-consume script runs.
2026-11-26 14:42:37 -08:00
stumpylog f0fdb0e51e Fix: move files per document during scheduled workflow runs
check_scheduled_workflows runs the workflow once per matched document inside the task-wide file move scope, so every rename it triggered was deferred to the end of the task. A long run killed by the Celery time limit would then discard all of the renames.

The task now flushes the pending file moves after each document's workflow run and websocket notification, the same way bulk_update_documents does, so renames land document by document while the scope stays open.
2026-11-26 14:42:37 -08:00
stumpylog 58b68767b3 Fix: rename and retag documents one file move at a time
document_renamer sent a fake post_save per document to trigger the move, and document_retagger moved a document once for each field it assigned.

The renamer calls move_files_for_document directly for each document, so progress reflects real work. The retagger opens a file move scope per document, so each document is moved once after all of its assignments.
2026-11-26 14:42:37 -08:00
stumpylog a66e52020f Fix: keep Celery's Django task base for file move scoped tasks
Passing task_cls to Celery replaces the Django fixup's default DjangoTask, so FileMoveScopedTask, built on the plain Task, left every task without delay_on_commit. The workflow AI suggestions trigger failed with an AttributeError.

FileMoveScopedTask now subclasses DjangoTask, which only needs django.db.transaction and is safe to import before apps load. The task scope test also asserts tasks are DjangoTask instances.
2026-11-26 14:42:37 -08:00
stumpylog e9d221a83f Fix: take media.lock before the consumer's storage transaction
Consuming a new version locked the root document row with select_for_update and then waited on media.lock to place the file, the same lock ordering that let concurrent saves deadlock. On MariaDB even the version row's foreign key check holds a shared lock on the root.

The consumer's storage phase now takes media.lock before opening its transaction and runs inside its own file move scope. File placement and workflow email actions inside the transaction re-enter the lock instead of waiting, and filename follow-ups run once after commit.
2026-11-26 14:42:36 -08:00
stumpylog 5e33952e6b Fix: take media.lock before emptying the trash
Emptying the trash deleted documents inside Django's delete transaction, and the post_delete file cleanup waited on media.lock while the deleted rows were locked. A concurrent file move holding media.lock and updating one of those rows could deadlock with it.

empty_trash now holds media.lock around the delete, so the cleanup handler re-enters the lock instead of waiting while rows are locked.
2026-11-26 14:42:36 -08:00
stumpylog bd6dda80e4 Fix: take media.lock before the archiver's transaction
The archiver updated the document row inside a transaction and then waited on media.lock. A concurrent file move holding media.lock and updating the same row could deadlock with it, and the unique archive filename was generated outside the lock from an instance loaded before the parse.

The archiver now acquires media.lock before opening its transaction, refreshes the document under the lock, and moves the archive and thumbnail inside that block, so it never waits on media.lock while holding the row.
2026-11-26 14:42:36 -08:00
stumpylog 1aed6ce3fd Fix: move document files once per Celery task
Tasks such as bulk_update_documents moved a document's files once for its manual post_save and again for every save its workflows made, each time taking the global media lock.

All tasks now run through FileMoveScopedTask, which opens a file move scope around the task body, including when the task raises. bulk_update_documents flushes after each document so long bulk edits still make steady progress.
2026-11-26 14:42:36 -08:00
stumpylog d3506c11cd Fix: move document files once per request, after its writes commit
A tag PATCH moved files from inside the tags.set() transaction while holding the document row lock. A concurrent save holding media.lock and waiting on that row deadlocked with it, and every later save on the instance queued behind media.lock until the webserver restarted.

FileMoveMiddleware opens a file move scope around every request, in sync or async mode, so each changed document is moved once after the view returns and never while a transaction holds row locks.
2026-11-26 14:42:36 -08:00
stumpylog a4b6c256d3 Fix: collect document file moves per scope and move once on exit
Each save of a document moved its files on the spot, so one logical change could move them several times, and moves could run inside another open transaction.

defer_file_moves() opens a ContextVar-backed scope. Inside it, move requests are recorded and the outermost scope moves each document once on exit, or on commit if a transaction is still open. A failing move is logged and does not stop the others. Outside any scope moves stay immediate.
2026-11-26 14:42:20 -08:00
stumpylog 610eb9ce41 Fix: extract document file moves out of the signal receiver
The file move receiver refreshed the caller's own instance from the database, which wiped unsaved in-memory changes. It ran on every m2m_changed action including pre_add and pre_remove, wrote modified even when nothing moved, and its no-move branch skipped trashed documents.

The move body now lives in documents.file_moves.move_files_for_document. It skips documents without a filename before taking media.lock, then takes the lock with a 300 second timeout, loads a fresh instance by pk, writes only when a filename column changes, and returns the instance. The receiver ignores reverse and pre_* m2m actions and copies just the final filename columns back onto the caller's instance.
2026-11-26 14:42:20 -08:00
stumpylog f57210d057 Fix: make the global media lock reentrant within a thread
Every caller built its own FileLock on media.lock, so code already holding it could not call into code that takes it again without blocking itself. That made it impossible to take media.lock before opening a transaction in paths that also attach files or move files inside that transaction.

media_lock() hands out one FileLock instance per path with per-thread hold counts, so a thread re-enters while other threads and processes stay excluded. All media.lock call sites now use it.
2026-11-26 14:42:20 -08:00
stumpylog b3faa38f15 Fix: stop full document saves from writing file path columns
A full save() of a Document instance loaded before another process moved its file wrote the old filename back. The DB then pointed at a path that no longer existed, and recovery only worked when the recomputed path happened to match the file's real location.

Document.save() now leaves filename and archive_filename out of full saves on existing rows. Writers that own those columns opt in with write_file_paths=True or an explicit update_fields. A full save of a row deleted elsewhere now raises instead of re-inserting it.
2026-11-26 14:42:19 -08:00
GitHub Actions 5c399653d7 Auto translate strings 2026-11-26 22:28:58 +00:00
5f6a071d36 Feature: OCR Templates (#14507)
---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Christoph Schlaepfer <1939311+Anuril@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: stumpylog <797416+stumpylog@users.noreply.github.com>
Co-authored-by: GitHub Actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
2026-11-26 14:27:46 -08:00
Trenton H f775b94cd6 Fix: flag recreated search index for reindex on next startup (#14877) 2026-11-26 09:57:00 -08:00
Trenton H b0dea5a07d Fix: clarify corrupted search index log tells user to run reindex (#14876) 2026-11-26 09:56:59 -08:00
shamoon 5ea1bd92c0 Fix/change: only split password list on new lines (#14869) 2026-11-25 15:55:24 -08:00
GitHub Actions 0a1bdad96b Auto translate strings 2026-11-25 23:54:55 +00:00
shamoon a139c2fd21 Fix/tweak: correct token throttling behind trusted proxies (#14862) 2026-11-25 23:53:47 +00:00
Trenton H 958bf8e34b Chore: switch sqlite-vec to the paperless-ngx patched wheels (#14838)
They are built from a patched fork that carries
upstream PRs including NEON on Linux arm64, memory-safety fixes and
performance improvements for both reading and cosine ranking
2026-11-25 18:12:57 +00:00
GitHub Actions 69142c043c Auto translate strings 2026-11-25 17:56:28 +00:00
Trenton H b9c7a21340 Enhancement: Answer chat questions from all retrieved chunks in one call (#14851)
* Enhancement: Answer chat questions from all retrieved chunks in one LLM call

The chat response synthesizer packed the retrieved chunks using the embedding
chunk size as its limit, so nothing merged and each question took 3 to 6
sequential LLM calls. Use the configured context size as the limit instead,
so the chunks share one prompt.

If the server rejects the larger prompt with a 400, log a warning naming
PAPERLESS_AI_LLM_CONTEXT_SIZE and retry once with the embedding chunk size,
as before. The retry only happens before anything has streamed.

* Fne, annotate chat synthesizer llm as LLM
2026-11-25 09:54:50 -08:00
Trenton H 2d83770098 Fix: Stream AI chat natively async so a disconnect cancels the LLM request (#14850)
* Fix: stream AI chat natively async so a disconnect cancels the LLM request

The chat answer was a sync generator wrapped for ASGI, pulling each chunk
through sync_to_async(next). A client disconnect cancelled the response
task, but the worker thread waiting on the LLM could not be interrupted,
so the upstream request kept generating the whole answer for nobody.

Make stream_chat_with_documents an async generator. All the blocking setup
(ORM queries, the index read lock and its thread-bound sqlite connection,
the query embedding, building the LLM client) moves into one sync
_prepare_chat called once through sync_to_async, which also hands the DB
connection back before the answer streams. The answer then streams through
llama-index's asynthesize over the pinned async httpx clients, so a
disconnect cancels the LLM request directly. The view returns the async
generator as is, replacing the sync-to-async wrapper.

The async pinned transport resolved hostnames with a blocking getaddrinfo
on the event loop, which would stall the whole worker on slow DNS now that
chat uses it in the web server. Resolve in a thread instead, and add the
async counterparts of the existing transport tests.

* Ensures all the resources are closed even in odd cases and not just by gc
2026-11-25 09:54:50 -08:00
GitHub Actions faa6f09f28 Auto translate strings 2026-11-23 19:47:58 +00:00
Trenton H 098694c6e4 Chore: Remove dead code (#14817)
* Chore: remove unused is_file_ext_supported

Nothing in production called it, only its own test.

* Chore: remove unused Tag.parent_pk

It was an alias of tn_parent_id used only by two test asserts, which now use tn_parent_id directly.

* Chore: remove unused SanityCheckMessages summary properties

has_global_issues was never referenced and total_issue_count was only asserted in tests. The two private issue counters that fed it are removed as well, and the tests assert on has_error and has_warning instead.

* Chore: remove unused DocumentViewSet._has_document_permissions

It duplicated has_document_operation_permissions and had no callers.

* Chore: remove legacy DocumentParser base class

Parsers are resolved through the parser registry and ParserProtocol now, and nothing referenced this class. Its now unused imports are removed too.

* Chore: remove unused ColorField and DeprecatedColors

No serializer used ColorField, and DeprecatedColors was only referenced by it.

* Chore: remove unused RtlLanguageException

A leftover from the old tesseract parser, nothing referenced it.

* Chore: remove unused TASK_WORKERS setting

An alias of CELERY_WORKER_CONCURRENCY that nothing read. PAPERLESS_TASK_WORKERS is unchanged.

* Chore: remove unused GNUPG_HOME setting

Nothing read it. The mail GPG code uses EMAIL_GNUPG_HOME.

* Chore: remove unused test helpers

Drops the shared_samples_dir fixture, MailAttachmentMock, _SHORT_TEXT and _make_extract_text, none of which any test used.
2026-11-23 19:46:34 +00:00
shamoon 0399008fb7 Fix: fix password removal for non-ASCII passwords on older PDFs (#14856) 2026-11-23 10:12:11 -08:00
shamoon f722730db7 mb-5 2026-11-22 13:21:40 -08:00
Trenton H 8866538369 Chore(deps): bump packages with open security advisories (#14810)
Clears the Dependabot alerts for twisted, autobahn, pyasn1, tornado and oauthlib.
2026-11-22 13:11:09 -08:00
Trenton H 245e819cb5 Chore: Bumps nltk to 3.10.4 to clear its 14 Dependabot alerts (#14811) 2026-11-22 10:42:18 -08:00
Trenton H 40fed2c70f Bumps psycopg-c to 3.3.8 (#14764) 2026-11-22 10:06:36 -08:00
shamoon 40598db447 Fix/tweak: include other loopbacks in default ALLOWED_HOSTS (#14846) 2026-11-22 09:27:53 -08:00
GitHub Actions d1e574ff8f Auto translate strings 2026-11-22 16:51:28 +00:00
shamoon 94ee54e4a6 Enhancement: nested tag 'split' display (#14843) 2026-11-22 08:49:24 -08:00
shamoon 51499afa5a Feature: What's new (in-app release notes) (#14835) 2026-11-22 16:48:54 +00:00
Trenton H d00da2b2ee Chore: bump jbig2enc to 0.32 (#14758) 2026-11-22 08:41:39 -08:00
Trenton H 4973be8499 Fix: Add socket timeout options for broker and celery during status API (#14824) 2026-11-19 07:20:11 -08:00
shamoon 14252054a1 Fix/tweak: update form inputs while typing (#14821) 2026-11-18 16:28:02 -08:00
github-actions[bot]andshamoon bcfdfcaa29 Documentation: Add v3.5.1 changelog (#14814)
* Changelog v3.5.1 - GHA

* Modify changelog for paperless-ngx version 3.5.1

Updated changelog to reflect changes in version 3.5.1.

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
2026-11-17 21:52:43 -08:00