From 74eb57203ba21f050b4bc744f11e0039c9b36cc2 Mon Sep 17 00:00:00 2001 From: Jonathan Kamens Date: Thu, 27 Feb 2025 20:18:08 -0500 Subject: [PATCH] fetch_next and fetch_previous shouldn't crash on last page When `fetch_next` reaches the last page, the `_pagination_next` attribute exists in the page structure but is set to None; similarly for `_pagination_prev` in `fetch_previous`. If this occurs we need to return `None` rather than trying to interate over `None` and generating an exception. --- mastodon/utility.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mastodon/utility.py b/mastodon/utility.py index 2270358..53dff34 100644 --- a/mastodon/utility.py +++ b/mastodon/utility.py @@ -134,6 +134,9 @@ class Mastodon(Internals): else: params = copy.deepcopy(previous_page) + if params is None: + return None + is_pagination_dict = False if isinstance(previous_page, dict): if all(key in ['_pagination_method', '_pagination_endpoint', 'min_id', 'max_id', 'since_id', 'limit'] for key in previous_page): @@ -173,6 +176,9 @@ class Mastodon(Internals): else: params = copy.deepcopy(next_page) + if params is None: + return None + is_pagination_dict = False if isinstance(next_page, dict): if all(key in ['_pagination_method', '_pagination_endpoint', 'min_id', 'max_id', 'since_id', 'limit'] for key in next_page):