mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-09-29 12:50:32 +00:00
Fix (beta): avoid DRF update calling save on all fields (#12992)
This commit is contained in:
@@ -24,6 +24,7 @@ from documents.models import CustomFieldInstance
|
||||
from documents.models import Document
|
||||
from documents.models import DocumentType
|
||||
from documents.models import StoragePath
|
||||
from documents.serialisers import DocumentSerializer
|
||||
from documents.tasks import empty_trash
|
||||
from documents.tests.factories import DocumentFactory
|
||||
from documents.tests.utils import DirectoriesMixin
|
||||
@@ -251,6 +252,46 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
self.assertIsNotFile(settings.ORIGINALS_DIR / "old" / "document.pdf")
|
||||
self.assertIsNotFile(settings.ARCHIVE_DIR / "old" / "document.pdf")
|
||||
|
||||
@override_settings(FILENAME_FORMAT="{title}")
|
||||
def test_serializer_stale_update_does_not_clobber_filename(self) -> None:
|
||||
old_path = settings.ORIGINALS_DIR / "original.pdf"
|
||||
old_path.touch()
|
||||
doc = Document.objects.create(
|
||||
title="original",
|
||||
mime_type="application/pdf",
|
||||
checksum=hashlib.sha256(b"").hexdigest(),
|
||||
filename="original.pdf",
|
||||
)
|
||||
|
||||
first_instance = Document.objects.get(pk=doc.pk)
|
||||
stale_instance = Document.objects.get(pk=doc.pk)
|
||||
|
||||
serializer = DocumentSerializer(
|
||||
first_instance,
|
||||
data={"title": "first"},
|
||||
partial=True,
|
||||
)
|
||||
self.assertTrue(serializer.is_valid(), serializer.errors)
|
||||
serializer.save()
|
||||
|
||||
doc.refresh_from_db()
|
||||
self.assertEqual(doc.filename, "first.pdf")
|
||||
self.assertIsFile(settings.ORIGINALS_DIR / "first.pdf")
|
||||
|
||||
serializer = DocumentSerializer(
|
||||
stale_instance,
|
||||
data={"title": "second"},
|
||||
partial=True,
|
||||
)
|
||||
self.assertTrue(serializer.is_valid(), serializer.errors)
|
||||
serializer.save()
|
||||
|
||||
doc.refresh_from_db()
|
||||
self.assertEqual(doc.filename, "second.pdf")
|
||||
self.assertIsFile(settings.ORIGINALS_DIR / "second.pdf")
|
||||
self.assertIsNotFile(settings.ORIGINALS_DIR / "first.pdf")
|
||||
self.assertIsNotFile(old_path)
|
||||
|
||||
@override_settings(FILENAME_FORMAT="{correspondent}/{correspondent}")
|
||||
def test_document_delete(self) -> None:
|
||||
document = Document()
|
||||
|
||||
Reference in New Issue
Block a user