mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-05 06:19:25 +00:00
Fix: move documents when tags change through the reverse relation
This commit is contained in:
1 parent
eb1a1fbf44
commit
8e09e44b83
2 files changed
+10
-6
No files matched your search
@@ -423,15 +423,18 @@ def update_filename_and_move_files(
|
||||
instance: Document | CustomFieldInstance,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
if kwargs.get("reverse"):
|
||||
# tag.documents.add(doc): instance is the Tag, not a Document.
|
||||
return
|
||||
action = kwargs.get("action")
|
||||
if action is not None and action not in {"post_add", "post_remove", "post_clear"}:
|
||||
# m2m_changed fires pre_* and post_* actions; only post_* describe the
|
||||
# relation state the filename should follow.
|
||||
return
|
||||
|
||||
if kwargs.get("reverse"):
|
||||
# tag.documents.add(doc): instance is the Tag, pk_set holds Document pks.
|
||||
for document in Document.objects.filter(pk__in=kwargs.get("pk_set") or ()):
|
||||
request_file_move(document)
|
||||
return
|
||||
|
||||
if isinstance(instance, CustomFieldInstance):
|
||||
if not _filename_template_uses_custom_fields(instance.document):
|
||||
return
|
||||
|
||||
@@ -256,7 +256,7 @@ class TestRequestFileMoveWithoutScope:
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestReceiver:
|
||||
def test_reverse_m2m_does_not_request_a_move(
|
||||
def test_reverse_m2m_requests_a_move_per_document(
|
||||
self,
|
||||
document: Document,
|
||||
mocker: MockerFixture,
|
||||
@@ -267,14 +267,15 @@ class TestReceiver:
|
||||
WHEN:
|
||||
- A document is added through the tag's reverse relation
|
||||
THEN:
|
||||
- No move is requested with the tag as the instance
|
||||
- A move is requested for the added document, never the tag
|
||||
"""
|
||||
tag = TagFactory()
|
||||
request = mocker.patch("documents.signals.handlers.request_file_move")
|
||||
|
||||
tag.documents.add(document)
|
||||
|
||||
request.assert_not_called()
|
||||
request.assert_called_once()
|
||||
assert request.call_args.args[0].pk == document.pk
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
Reference in new issue
Block a user