fix: guard get_next/get_previous against unset _more - #120
Open
CedricConday wants to merge 1 commit into
Open
Conversation
ResultSet._more is a declared Pydantic private attribute defaulting to None, so hasattr(self, "_more") is always True and the existing guard never triggers. When _more is not set (e.g. a ResultSet not produced by the @returns decorator), get_next()/get_previous() called None(**params) and raised "'NoneType' object is not callable". Guard on `self._more is None` instead so these methods return None as intended. Adds a regression test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ResultSet.get_next()/get_previous()guard withnot hasattr(self, "_more"), but_moreis a declared Pydantic private attribute with a default ofNone:Because the attribute is declared,
hasattr(self, "_more")is alwaysTrue(it resolves to the defaultNone), so the guard never short-circuits. When_morehas not been set — e.g. aResultSetthat wasn't produced by the@returnsdecorator — the methods fall through toself._more(**params)and raise:This changes the guard to
self._more is None, soget_next()/get_previous()returnNoneas intended when there is no callable to page with. The normal decorator-driven flow (where_moreis afunctools.partial) is unchanged.Testing
Added
test_resultset_without_more_returns_none, which constructs aResultSetwithnext/previousset but no_moreand asserts both accessors returnNone. Before the change this test raisedTypeError; the existingtest_resultset(decorator-driven paging) continues to pass.