Skip to content

Commit c980657

Browse files
temrjanclaude
andcommitted
fix: compute totalPages from unpaginated count query
The objects_count query reused the same SELECT that already had LIMIT/OFFSET applied, so count() always returned at most page_size rows, making totalPages always 1 regardless of actual row count. Build a separate count query with only filters and joins (no pagination) so that totalPages reflects the true number of pages. Closes #103 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a1a4fc5 commit c980657

File tree

1 file changed

+7
-1
lines changed
  • fastapi_jsonapi/data_layers/sqla

1 file changed

+7
-1
lines changed

fastapi_jsonapi/data_layers/sqla/orm.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,15 @@ async def get_collection(
425425

426426
objects_count = self.default_collection_count
427427
if not self.disable_collection_count:
428+
count_query = self._base_sql.query(
429+
model=self.model,
430+
filters=filters,
431+
jsonapi_join=relationships_info,
432+
stmt=self._query,
433+
)
428434
objects_count = await self._base_sql.count(
429435
session=self.session,
430-
stmt=query,
436+
stmt=count_query,
431437
)
432438

433439
collection = await self.after_get_collection(collection, qs, view_kwargs)

0 commit comments

Comments
 (0)