From 21557b2a47f421c2112b9564029d51fdad517620 Mon Sep 17 00:00:00 2001 From: Shuotian Cheng Date: Tue, 23 Jan 2024 10:49:23 -0800 Subject: [PATCH] Fix Python Paging Infinite Issue Summary: This diff fixes a bug in the Python SDK for Facebook Business where the paging cursor was not properly checked for the existence of the 'next' key, which caused an infinite loop when there were no more pages to fetch. The code changes in the 'api.py' file of the SDK and the 'facebook_business/api.py' file of the codegen templates ensure that the 'after' cursor is only set if the 'next' key exists in the paging information. This should prevent the infinite loop and allow the SDK to properly handle paging in the API calls. Reviewed By: mengxuanzhangz Differential Revision: D53010767 fbshipit-source-id: 6588814b8fb48be213bedc4b7e304aeecdca0211 --- facebook_business/api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/facebook_business/api.py b/facebook_business/api.py index 1ec9d880..0c6dab7b 100644 --- a/facebook_business/api.py +++ b/facebook_business/api.py @@ -835,7 +835,9 @@ def load_next_page(self): if ( 'paging' in response and 'cursors' in response['paging'] and - 'after' in response['paging']['cursors'] + 'after' in response['paging']['cursors'] and + # 'after' will always exist even if no more pages are available + 'next' in response['paging'] ): self.params['after'] = response['paging']['cursors']['after'] else: