diff --git a/slack_sdk/web/internal_utils.py b/slack_sdk/web/internal_utils.py index 2c34e585..c7d14562 100644 --- a/slack_sdk/web/internal_utils.py +++ b/slack_sdk/web/internal_utils.py @@ -230,9 +230,10 @@ def _next_cursor_is_present(data) -> bool: A boolean value. """ # Only admin.conversations.search returns next_cursor at the top level - present = ("next_cursor" in data and data["next_cursor"] != "") or ( + present = ("next_cursor" in data and data["next_cursor"] is not None and data["next_cursor"] != "") or ( "response_metadata" in data and "next_cursor" in data["response_metadata"] + and data["response_metadata"]["next_cursor"] is not None and data["response_metadata"]["next_cursor"] != "" ) return present diff --git a/tests/slack_sdk/web/test_internal_utils.py b/tests/slack_sdk/web/test_internal_utils.py index dfac719b..13da2c1a 100644 --- a/tests/slack_sdk/web/test_internal_utils.py +++ b/tests/slack_sdk/web/test_internal_utils.py @@ -11,6 +11,7 @@ _build_unexpected_body_error_message, _parse_web_class_objects, _to_v2_file_upload_item, + _next_cursor_is_present, ) @@ -98,3 +99,12 @@ def test_files_upload_v2_issue_1356(self): assert file_io_item.get("filename") == "Uploaded file" file_io_item = _to_v2_file_upload_item({"file": file_io, "filename": "foo.txt"}) assert file_io_item.get("filename") == "foo.txt" + + def test_next_cursor_is_present(self): + assert _next_cursor_is_present({"next_cursor": "next-page"}) is True + assert _next_cursor_is_present({"next_cursor": ""}) is False + assert _next_cursor_is_present({"next_cursor": None}) is False + assert _next_cursor_is_present({"response_metadata": {"next_cursor": "next-page"}}) is True + assert _next_cursor_is_present({"response_metadata": {"next_cursor": ""}}) is False + assert _next_cursor_is_present({"response_metadata": {"next_cursor": None}}) is False + assert _next_cursor_is_present({"something_else": {"next_cursor": "next-page"}}) is False