Skip to content

Commit 9967dc0

Browse files
authored
Make next_cursor extraction logic even more robust (ref #1407) (#1409)
1 parent 2caacbb commit 9967dc0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

slack_sdk/web/internal_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,10 @@ def _next_cursor_is_present(data) -> bool:
230230
A boolean value.
231231
"""
232232
# Only admin.conversations.search returns next_cursor at the top level
233-
present = ("next_cursor" in data and data["next_cursor"] != "") or (
233+
present = ("next_cursor" in data and data["next_cursor"] is not None and data["next_cursor"] != "") or (
234234
"response_metadata" in data
235235
and "next_cursor" in data["response_metadata"]
236+
and data["response_metadata"]["next_cursor"] is not None
236237
and data["response_metadata"]["next_cursor"] != ""
237238
)
238239
return present

tests/slack_sdk/web/test_internal_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
_build_unexpected_body_error_message,
1212
_parse_web_class_objects,
1313
_to_v2_file_upload_item,
14+
_next_cursor_is_present,
1415
)
1516

1617

@@ -98,3 +99,12 @@ def test_files_upload_v2_issue_1356(self):
9899
assert file_io_item.get("filename") == "Uploaded file"
99100
file_io_item = _to_v2_file_upload_item({"file": file_io, "filename": "foo.txt"})
100101
assert file_io_item.get("filename") == "foo.txt"
102+
103+
def test_next_cursor_is_present(self):
104+
assert _next_cursor_is_present({"next_cursor": "next-page"}) is True
105+
assert _next_cursor_is_present({"next_cursor": ""}) is False
106+
assert _next_cursor_is_present({"next_cursor": None}) is False
107+
assert _next_cursor_is_present({"response_metadata": {"next_cursor": "next-page"}}) is True
108+
assert _next_cursor_is_present({"response_metadata": {"next_cursor": ""}}) is False
109+
assert _next_cursor_is_present({"response_metadata": {"next_cursor": None}}) is False
110+
assert _next_cursor_is_present({"something_else": {"next_cursor": "next-page"}}) is False

0 commit comments

Comments
 (0)