Skip to content

Commit 4620c20

Browse files
authored
Fix bug with optional params and page creation (#608)
1 parent 5edee9b commit 4620c20

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

fastapi_pagination/default.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ def create(
5959
if not isinstance(params, Params):
6060
raise ValueError("Page should be used with Params")
6161

62-
pages = ceil(total / params.size) if total is not None else None
62+
size = params.size if params.size is not None else total
63+
page = params.page if params.page is not None else 1
64+
pages = ceil(total / size) if total is not None else None
6365

6466
return cls(
6567
total=total, # type: ignore[arg-type]
6668
items=items,
67-
page=params.page,
68-
size=params.size,
69+
page=page,
70+
size=size,
6971
pages=pages,
7072
**kwargs,
7173
)

0 commit comments

Comments
 (0)