Skip to content

Commit b75d4e0

Browse files
committed
allow absurd page sizes
1 parent a81abf7 commit b75d4e0

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

trove/trovesearch/page_cursor.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
MANY_MORE = -1
1515
MAX_OFFSET = 9997
1616

17+
DEFAULT_PAGE_SIZE = 13
18+
MAX_PAGE_SIZE = 9997
19+
1720

1821
@dataclasses.dataclass
1922
class PageCursor:
20-
page_size: int
23+
page_size: int = DEFAULT_PAGE_SIZE
2124
total_count: int = MANY_MORE
2225

2326
@classmethod
@@ -36,6 +39,10 @@ def from_cursor(cls, other_cursor: PageCursor) -> typing.Self:
3639
return dataclasses.replace(other_cursor) # simple copy
3740
return cls(*dataclasses.astuple(other_cursor))
3841

42+
def __post_init__(self):
43+
if self.page_size > MAX_PAGE_SIZE:
44+
self.page_size = MAX_PAGE_SIZE
45+
3946
def as_queryparam_value(self) -> str:
4047
_cls_key = _PageCursorTypes(type(self)).name
4148
_as_json = json.dumps([_cls_key, *dataclasses.astuple(self)])

trove/trovesearch/search_params.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
from primitive_metadata import primitive_rdf
1212

1313
from trove import exceptions as trove_exceptions
14-
from trove.trovesearch.page_cursor import PageCursor
14+
from trove.trovesearch.page_cursor import (
15+
DEFAULT_PAGE_SIZE,
16+
PageCursor,
17+
)
1518
from trove.util.queryparams import (
1619
QueryparamDict,
1720
QueryparamName,
@@ -47,10 +50,6 @@
4750
# optional prefix for "sort" values
4851
DESCENDING_SORT_PREFIX = '-'
4952

50-
# for "page[size]" values
51-
DEFAULT_PAGE_SIZE = 13
52-
MAX_PAGE_SIZE = 101
53-
5453
# between each step in a property path "foo.bar.baz"
5554
PROPERTYPATH_DELIMITER = '.'
5655

@@ -671,11 +670,11 @@ def _get_page_cursor(queryparams: QueryparamDict) -> PageCursor:
671670
_cursor_value = _get_single_value(queryparams, QueryparamName('page', ('cursor',)))
672671
if _cursor_value:
673672
return PageCursor.from_queryparam_value(_cursor_value)
673+
_size_value = _get_single_value(queryparams, QueryparamName('page', ('size',)))
674+
if _size_value is None:
675+
return PageCursor()
674676
try:
675-
_size = int( # TODO: 400 response on non-int value
676-
_get_single_value(queryparams, QueryparamName('page', ('size',)))
677-
or DEFAULT_PAGE_SIZE
678-
)
677+
_size = int(_size_value)
679678
except ValueError:
680679
raise trove_exceptions.InvalidQueryParamValue('page[size]')
681-
return PageCursor(page_size=min(_size, MAX_PAGE_SIZE))
680+
return PageCursor(page_size=_size)

0 commit comments

Comments
 (0)