Remove backend max atoms / depth settings

This commit is contained in:
shamoon 2024-09-05 16:51:45 -07:00
parent 028e5245e8
commit 301e875308
3 changed files with 7 additions and 33 deletions

View File

@ -81,7 +81,6 @@
#PAPERLESS_THUMBNAIL_FONT_NAME= #PAPERLESS_THUMBNAIL_FONT_NAME=
#PAPERLESS_IGNORE_DATES= #PAPERLESS_IGNORE_DATES=
#PAPERLESS_ENABLE_UPDATE_CHECK= #PAPERLESS_ENABLE_UPDATE_CHECK=
#PAPERLESS_ALLOW_CUSTOM_FIELD_LOOKUP=iexact,contains,startswith,endswith,regex,iregex
# Tika settings # Tika settings

View File

@ -30,13 +30,15 @@ from documents.models import Log
from documents.models import ShareLink from documents.models import ShareLink
from documents.models import StoragePath from documents.models import StoragePath
from documents.models import Tag from documents.models import Tag
from paperless import settings
CHAR_KWARGS = ["istartswith", "iendswith", "icontains", "iexact"] CHAR_KWARGS = ["istartswith", "iendswith", "icontains", "iexact"]
ID_KWARGS = ["in", "exact"] ID_KWARGS = ["in", "exact"]
INT_KWARGS = ["exact", "gt", "gte", "lt", "lte", "isnull"] INT_KWARGS = ["exact", "gt", "gte", "lt", "lte", "isnull"]
DATE_KWARGS = ["year", "month", "day", "date__gt", "gt", "date__lt", "lt"] DATE_KWARGS = ["year", "month", "day", "date__gt", "gt", "date__lt", "lt"]
CUSTOM_FIELD_LOOKUP_MAX_DEPTH = 10
CUSTOM_FIELD_LOOKUP_MAX_ATOMS = 20
class CorrespondentFilterSet(FilterSet): class CorrespondentFilterSet(FilterSet):
class Meta: class Meta:
@ -394,13 +396,7 @@ class CustomFieldLookupParser:
self._atom_count += 1 self._atom_count += 1
if self._atom_count > self._max_atom_count: if self._atom_count > self._max_atom_count:
raise serializers.ValidationError( raise serializers.ValidationError(
[ [_("Maximum number of query conditions exceeded.")],
_(
"Maximum number of query conditions exceeded. You can raise "
"the limit by setting PAPERLESS_CUSTOM_FIELD_LOOKUP_MAX_ATOMS "
"in your configuration file.",
),
],
) )
custom_field = self._get_custom_field(id_or_name, validation_prefix="0") custom_field = self._get_custom_field(id_or_name, validation_prefix="0")
@ -597,15 +593,7 @@ class CustomFieldLookupParser:
# guard against queries that are too deeply nested # guard against queries that are too deeply nested
self._current_depth += 1 self._current_depth += 1
if self._current_depth > self._max_query_depth: if self._current_depth > self._max_query_depth:
raise serializers.ValidationError( raise serializers.ValidationError([_("Maximum nesting depth exceeded.")])
[
_(
"Maximum nesting depth exceeded. You can raise the limit "
"by setting PAPERLESS_CUSTOM_FIELD_LOOKUP_MAX_DEPTH in "
"your configuration file.",
),
],
)
try: try:
yield yield
finally: finally:
@ -629,8 +617,8 @@ class CustomFieldLookupFilter(Filter):
parser = CustomFieldLookupParser( parser = CustomFieldLookupParser(
self._validation_prefix, self._validation_prefix,
max_query_depth=settings.CUSTOM_FIELD_LOOKUP_MAX_DEPTH, max_query_depth=CUSTOM_FIELD_LOOKUP_MAX_DEPTH,
max_atom_count=settings.CUSTOM_FIELD_LOOKUP_MAX_ATOMS, max_atom_count=CUSTOM_FIELD_LOOKUP_MAX_ATOMS,
) )
q, annotations = parser.parse(value) q, annotations = parser.parse(value)

View File

@ -1195,16 +1195,3 @@ EMAIL_ENABLE_GPG_DECRYPTOR: Final[bool] = __get_boolean(
# Soft Delete # # Soft Delete #
############################################################################### ###############################################################################
EMPTY_TRASH_DELAY = max(__get_int("PAPERLESS_EMPTY_TRASH_DELAY", 30), 1) EMPTY_TRASH_DELAY = max(__get_int("PAPERLESS_EMPTY_TRASH_DELAY", 30), 1)
###############################################################################
# custom_field_lookup Filter Settings #
###############################################################################
CUSTOM_FIELD_LOOKUP_MAX_DEPTH = __get_int(
"PAPERLESS_CUSTOM_FIELD_LOOKUP_MAX_DEPTH",
default=10,
)
CUSTOM_FIELD_LOOKUP_MAX_ATOMS = __get_int(
"PAPERLESS_CUSTOM_FIELD_LOOKUP_MAX_ATOMS",
default=20,
)