fastapi-pagination: LimitOffsetParams don't work
This way pagination works fine:
from fastapi_pagination import pagination_params
When switching to limit-offset version:
from fastapi_pagination.limit_offset import pagination_params
same code and adjusted request fail with: "Page should be used with PaginationParams"
Request:
http://0.0.0.0:8080/api/v1/call_records?date_from=2021-01-01&date_till=2021-02-01&limit=50&offset=0
Endpoint:
@router.get('/call_records', response_model=Page[CallRecord], dependencies=[Depends(pagination_params)], tags=['calls'])
@handle_exceptions
async def get_call_records(date_from: datetime.date, date_till: datetime.date):
records = await core.get_call_records(database, date_from, date_till, None)
page = paginate(records)
return page
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 15 (14 by maintainers)
Commits related to this issue
- 📝 Add docs and example for limit-offset #4 — committed to uriyyo/fastapi-pagination by uriyyo 3 years ago
Hmm, upon further testing it seems that the exporting keeps failing when Uvicorn reloads. Sometimes, it exports to OpenAPI schema correctly and is shown on the docs, but most of the time only a few routes are exported. Despite not being exported to the schema, the route still works as expected.
Will report back with code that can reproduce the error.
With new implementation, every
Pageclass hasParamstype associated with it. Basically,Pageclass has__params_type__attribute wich is pointing toParamsclass.For instance, how to create change default
Params:Can you try to use this example?
In case if you want to use another page model you must call
using_pagefunction with page model class.