Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

prevent usage of {tags} directly.

jonaswinkler8cc033633812
diff --git a/src/documents/file_handling.py b/src/documents/file_handling.py
index 861eb2a37..c49493991 100644
--- a/src/documents/file_handling.py
+++ b/src/documents/file_handling.py
@@ -8,6 +8,12 @@ from django.conf import settings
from django.template.defaultfilters import slugify
+class defaultdictNoStr(defaultdict):
+
+ def __str__(self):
+ raise ValueError("Don't use {tags} directly.")
+
+
def create_source_path_directory(source_path):
os.makedirs(os.path.dirname(source_path), exist_ok=True)
@@ -90,8 +96,8 @@ def generate_filename(doc, counter=0):
try:
if settings.PAPERLESS_FILENAME_FORMAT is not None:
- tags = defaultdict(lambda: slugify(None),
- many_to_dictionary(doc.tags))
+ tags = defaultdictNoStr(lambda: slugify(None),
+ many_to_dictionary(doc.tags))
if doc.correspondent:
correspondent = pathvalidate.sanitize_filename(
diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.py
index 2f7f6efcf..dec89c45b 100644
--- a/src/documents/tests/test_file_handling.py
+++ b/src/documents/tests/test_file_handling.py
@@ -267,6 +267,15 @@ class TestFileHandling(DirectoriesMixin, TestCase):
self.assertEqual(generate_filename(document),
"none.pdf")
+ @override_settings(PAPERLESS_FILENAME_FORMAT="{tags}")
+ def test_tags_without_args(self):
+ document = Document()
+ document.mime_type = "application/pdf"
+ document.storage_type = Document.STORAGE_TYPE_UNENCRYPTED
+ document.save()
+
+ self.assertEqual(generate_filename(document), f"{document.pk:07}.pdf")
+
@override_settings(PAPERLESS_FILENAME_FORMAT="{title} {tag_list}")
def test_tag_list(self):
doc = Document.objects.create(title="doc1", mime_type="application/pdf")