Skip to content

[Bug]: Incorrect Pagination Calculation in API Endpoints #191

Description

@AryanYadav215

Bug description

[Bug]: Incorrect Pagination Calculation in API Endpoints

Description

As an ECSoC'26 contributor reviewing the backend endpoints (referencing the file kepler.pdf verbatim), I identified a logical bug in the pagination calculations across several FastAPI routes[cite: 1].

Issues Identified

Across multiple endpoints (such as /collisions, /agents, and /weather), the calculation for the total number of pages is mathematically incomplete[cite: 1].
The code currently evaluates:
pages = (total + size - 1)[cite: 1]

This calculation is missing the integer division operation by the page size, meaning the API returns wildly inaccurate page counts[cite: 1].

Steps to Reproduce

  1. Make a GET request to /api/v1/collisions or /api/v1/agents/runs with size=10 and a total of 50 records[cite: 1].
  2. Observe that the API returns pages=59 instead of the correct value of 5[cite: 1].

Steps to reproduce

Steps to Reproduce

  1. Make a GET request to /api/v1/collisions or /api/v1/agents/runs with size=10 and a total of 50 records[cite: 1].
  2. Observe that the API metadata returns pages=59 instead of the correct value of 5[cite: 1].

Expected behavior

Expected Behavior

The API calculates the pages field correctly using integer division, yielding an accurate total page count based on the number of records and the requested page size[cite: 1].

Actual behavior

Actual Behavior

The code currently evaluates the total pages using simple addition and subtraction: pages = (total + size - 1)[cite: 1]. Because it lacks the final division operation by the page size, the API returns wildly inaccurate and inflated page counts[cite: 1].

Screenshots or recordings

No response

Platform

API

Environment

No response

Error messages or logs

Difficulty

None

Priority

None

Additional information

No response

Metadata

Metadata

Assignees

Labels

apiRelated to APIs or backend endpoints.assignedIndicates that the issue has been assigned to a contributor who is actively working on it.backendBackend developmentbugSomething isn't workingenhancementNew feature or requesttype:backendChanges backend services or server-side logic.type:bugFixes an existing bug or unexpected behavior.type:featureIntroduces a new feature or enhancement.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions