Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions predicthq/endpoints/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def has_next(self):
return self.next is not None

def get_next(self):
if not self.has_next() or not hasattr(self, "_more"):
if not self.has_next() or self._more is None:
return
params = self._parse_params(self.next)
return self._more(**params)

def get_previous(self):
if not self.has_previous() or not hasattr(self, "_more"):
if not self.has_previous() or self._more is None:
return
params = self._parse_params(self.previous)
return self._more(**params)
Expand Down
16 changes: 16 additions & 0 deletions tests/endpoints/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,19 @@ def load_page(self, page):
endpoint.load_page(page=3).model_dump(),
]
assert list(p1.iter_all()) == list(p1) + list(p2) + list(p3)


def test_resultset_without_more_returns_none():
# A ResultSet not produced by the @returns decorator has no _more callable set.
# _more is a declared private attr defaulting to None, so hasattr() is always
# True; get_next()/get_previous() must guard on `_more is None` and return None
# rather than raising "'NoneType' object is not callable".
result_set = schemas.ResultSet(
count=5,
next="https://example.org/?page=2",
previous="https://example.org/?page=1",
)
assert result_set.has_next() is True
assert result_set.has_previous() is True
assert result_set.get_next() is None
assert result_set.get_previous() is None