mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-06-21 08:24:07 -04:00
Do not allow a None-limit on PaginationConfig. (#14146)
The callers either set a default limit or manually handle a None-limit later on (by setting a default value). Update the callers to always instantiate PaginationConfig with a default limit and then assume the limit is non-None.
This commit is contained in:
parent
c7446906bd
commit
126a15794c
16 changed files with 29 additions and 50 deletions
|
@ -35,14 +35,14 @@ class PaginationConfig:
|
|||
from_token: Optional[StreamToken]
|
||||
to_token: Optional[StreamToken]
|
||||
direction: str
|
||||
limit: Optional[int]
|
||||
limit: int
|
||||
|
||||
@classmethod
|
||||
async def from_request(
|
||||
cls,
|
||||
store: "DataStore",
|
||||
request: SynapseRequest,
|
||||
default_limit: Optional[int] = None,
|
||||
default_limit: int,
|
||||
default_dir: str = "f",
|
||||
) -> "PaginationConfig":
|
||||
direction = parse_string(
|
||||
|
@ -69,12 +69,10 @@ class PaginationConfig:
|
|||
raise SynapseError(400, "'to' parameter is invalid")
|
||||
|
||||
limit = parse_integer(request, "limit", default=default_limit)
|
||||
if limit < 0:
|
||||
raise SynapseError(400, "Limit must be 0 or above")
|
||||
|
||||
if limit:
|
||||
if limit < 0:
|
||||
raise SynapseError(400, "Limit must be 0 or above")
|
||||
|
||||
limit = min(int(limit), MAX_LIMIT)
|
||||
limit = min(limit, MAX_LIMIT)
|
||||
|
||||
try:
|
||||
return PaginationConfig(from_tok, to_tok, direction, limit)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue