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.
This commit is contained in:
stumpylog committed 2026-11-03 15:09:29 -08:00
1 parent fc29f3511f
commit 08748baf54
8 files changed
+152 -19

No files matched your search

+3 -3
View File
@@ -739,7 +739,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
mime_type="application/pdf",
)
self.doc1.archive_filename = sample1_archive
self.doc1.save()
self.doc1.save(write_file_paths=True)
self.doc2 = Document.objects.create(
checksum="B",
title="B",
@@ -749,7 +749,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
created=date(2023, 1, 2),
)
self.doc2.archive_filename = sample2_archive
self.doc2.save()
self.doc2.save(write_file_paths=True)
self.doc3 = Document.objects.create(
checksum="C",
title="C",
@@ -774,7 +774,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
created=date(2023, 1, 3),
)
self.img_doc.archive_filename = img_doc_archive
self.img_doc.save()
self.img_doc.save(write_file_paths=True)
@staticmethod
def fake_decrypt(