Skip to content

Conversation

@idoshr
Copy link
Owner

@idoshr idoshr commented Oct 31, 2025

No description provided.

Documented 6 bugs found during code review:
- Critical: Division by zero with per_page=0
- Critical: Negative per_page values cause undefined behavior
- Medium: iter_pages() left_edge calculation incorrect with custom first_page_index
- Medium: iter_pages() right_edge calculation incorrect with custom first_page_index
- Low: Useless assert NotImplementedError in KeysetPagination.prev()
- Low: prev_num/next_num don't check boundaries

Each bug includes detailed description, reproduction steps, and proposed fixes.
Fixes Bug #4 and Bug #5 from BUG_REPORT.md

Changes:
- Add validation in all pagination classes to reject per_page <= 0
- Raises ValueError with clear message when per_page is invalid
- Prevents ZeroDivisionError crashes when per_page=0
- Prevents undefined behavior with negative per_page values

Modified files:
- flask_mongoengine/pagination/basic_pagination.py
- flask_mongoengine/pagination/keyset_pagination.py
- flask_mongoengine/pagination/list_field_pagination.py

Added comprehensive test coverage:
- tests/test_pagination.py: test_per_page_validation()
  - Tests per_page=0 for all pagination classes
  - Tests negative per_page for all pagination classes
  - Verifies correct ValueError is raised with proper message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants