From 58b508b898b1ce82e75c502d3a2b8d7a56b48006 Mon Sep 17 00:00:00 2001 From: Deep Prajapati <47732985+deepprajapati18@users.noreply.github.com> Date: Sat, 27 Feb 2021 00:26:38 +0530 Subject: [PATCH] fix execution of execute and load_next_page method There is a bug while working with Facebook request API, that is not giving all the elements as it is returning 25 elements. So by checking the execute method of the FacebookRequest, I notice one thing that, it is calling only for the first paginated elements and the default returning limit is 25 so It is returning only first page data, and will not check for the next page. So in the execute method of FacebookRequest, there is a method called load_next_page which is the method of the Cursor, which is calling the graph API but it will run only for the first time and it will not check the next page of data. So I updated it like: add a while loop and check the status of the load_next_page and store the result in the status. So if the status will True then It will check the re-execute the load_next_page, which will call the next page graph API as on every execution of load_next_page, URL-PATH which is self._path, will update to next page URL. And this process will continue until there is no Next Page URL. If there is not Next Page URL then self._finished_iteration from Cursor will set to True and when the load_next_page will run again then it first checks if self._finished_iteration then return False. And we will store this value in the status which is in the loop of the execute method of FacebookRequest. So when the status will False break the loop and continue the process as it is already there. --- facebook_business/api.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/facebook_business/api.py b/facebook_business/api.py index 2a408c839..439facd99 100644 --- a/facebook_business/api.py +++ b/facebook_business/api.py @@ -674,7 +674,10 @@ def execute(self): node_id=self._node_id, endpoint=self._endpoint, ) - cursor.load_next_page() + while True: + status = cursor.load_next_page() + if status == False: + break return cursor if self._fields: params['fields'] = ','.join(self._fields) @@ -863,7 +866,7 @@ def load_next_page(self): if self._include_summary and 'summary' in response: self._summary = response['summary'] - self._queue = self.build_objects_from_response(response) + self._queue.extend(self.build_objects_from_response(response)) return len(self._queue) > 0 def get_one(self):