Skip to content

Failing to set PAGE_SIZE and using LimitOffsetPagination can raise unexpected error #3692

Closed
@kezabelle

Description

@kezabelle

Specifically,
if api_settings.PAGE_SIZE is None (default) and one manually calls LimitOffsetPagination.paginate_queryset(...) followed by LimitOffsetPagination.get_paginated_response(...), get_paginated_response will raise an AttributeError because self.count is never set.

I'm not going to argue the merits of why it's been manually called (because I didn't write the code, only encountered it), but the resulting exception is not useful for debugging the cause, as the rest of the code all assumes self.count can only be an integer (true only if _get_count is called, which requires self.limit to not be None)

The simplest "fix" is to assert hasattr(self, 'count') and self.count is not None and emit a better error message that explains the situation, as anything more would need to be more invasive (affecting get_next/previous_link methods etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions