uriyyo / fastapi-pagination

FastAPI pagination 📖
https://uriyyo-fastapi-pagination.netlify.app/
MIT License
1.1k stars 126 forks source link

fix incorrect total number in page when paginating beanie query with fetch_links=True #1199

Closed IterableTrucks closed 5 days ago

IterableTrucks commented 1 week ago

Beanie's find_many method will modify the limit and offset number of the query. When querying with fetch_links=False as default, this will not be a problem, but when fetch_links=True the implicitly created aggregation pipeline will add limit and skip stages which is incorrect to count the total number. To fix this problem, count query should be placed before items query and the fetch_links should respect the parameter's value in paginate method.

codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 92.69%. Comparing base (245519c) to head (b76c621). Report is 282 commits behind head on main.

Files Patch % Lines
fastapi_pagination/ext/beanie.py 66.66% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1199 +/- ## ========================================== - Coverage 93.26% 92.69% -0.58% ========================================== Files 35 38 +3 Lines 1040 1314 +274 ========================================== + Hits 970 1218 +248 - Misses 70 96 +26 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

uriyyo commented 1 week ago

@IterableTrucks Could you please fix lint errors?