]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix typing issue
authorshamoon <4887959+shamoon@users.noreply.github.com>
Mon, 16 Feb 2026 17:17:20 +0000 (09:17 -0800)
committershamoon <4887959+shamoon@users.noreply.github.com>
Mon, 16 Feb 2026 17:17:20 +0000 (09:17 -0800)
src/documents/views.py

index 5d78d1b48b73a919dd424f68ec7070cffb775275..420e8fb1e75e7a4c3446bad726f6044b4c67c9d8 100644 (file)
@@ -390,7 +390,16 @@ class PermissionsAwareDocumentCountMixin(BulkPermissionMixin, PassUserMixin):
 
     # Default is simple relation path, override for through-table/count specialization.
     document_count_through = None
-    document_count_source_field = None
+    document_count_source_field: str | None = None
+
+    def _get_document_count_source_field(self) -> str:
+        if self.document_count_source_field is None:
+            msg = (
+                "document_count_source_field must be set when "
+                "document_count_through is configured"
+            )
+            raise ValueError(msg)
+        return self.document_count_source_field
 
     def get_document_count_filter(self):
         request = getattr(self, "request", None)
@@ -406,7 +415,7 @@ class PermissionsAwareDocumentCountMixin(BulkPermissionMixin, PassUserMixin):
             return annotate_document_count_for_related_queryset(
                 base_qs,
                 through_model=self.document_count_through,
-                related_object_field=self.document_count_source_field,
+                related_object_field=self._get_document_count_source_field(),
                 user=user,
             )
 
@@ -508,7 +517,7 @@ class TagViewSet(PermissionsAwareDocumentCountMixin, ModelViewSet):
                     .select_related("owner")
                     .order_by(*ordering),
                     through_model=self.document_count_through,
-                    related_object_field=self.document_count_source_field,
+                    related_object_field=self._get_document_count_source_field(),
                     user=user,
                 ),
             )