facebook / facebook-python-business-sdk

Python SDK for Meta Marketing APIs
https://developers.facebook.com/docs/business-sdk
Other
1.28k stars 631 forks source link

Fix bug with pagination #569

Closed SlavaSkvortsov closed 3 years ago

SlavaSkvortsov commented 4 years ago

It should be a dict -_- Could you use Mypy or test or, better, both?

facebook-github-bot commented 4 years ago

Hi @SlavaSkvortsov!

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

facebook-github-bot commented 4 years ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

nandanrao commented 4 years ago

omg thank you @SlavaSkvortsov...

nathand8 commented 4 years ago

Can we get this merged and released plz?

jen-soft commented 4 years ago
class Cursor(object):

    def load_next_page(self):
        """Queries server for more nodes and loads them into the internal queue.
        Returns:
            True if successful, else False.
        """
        if self._finished_iteration:
            return False

        if (
            self._include_summary and
            'default_summary' not in self.params and
            'summary' not in self.params
        ):
            self.params['summary'] = True  # <==============================================(! 1)

        response_obj = self._api.call(
            'GET',
            self._path,
            params=self.params,
        )
        response = response_obj.json()
        self._headers = response_obj.headers()

        if 'paging' in response and 'next' in response['paging']:
            self._path = response['paging']['next']
            self.params = []  # <==============================================(! 2)
        else:
            # Indicate if this was the last page
            self._finished_iteration = True
jen-soft commented 4 years ago

quick fix outside of library

    def get_ad_accounts(self):
        fb_user = fb.User('me', api=self._api)
        _request = fb_user.get_ad_accounts(
            fields=[
                fb.AdAccount.Field.id,
                fb.AdAccount.Field.account_id,
                fb.AdAccount.Field.name,
                fb.AdAccount.Field.account_status,
                fb.AdAccount.Field.currency,
                fb.AdAccount.Field.timezone_id,
            ],
            pending=True
        )
        #
        response = _request.execute()
        # ------------------------------------------------------------ #
        result = []
        for item in response:
            # fixme: remove after facebook will fix it
            # from facebook_business.api import Cursor
            # - - -
            if isinstance(response.params, list):
                assert len(response.params) == 0
                response.params = {} # <=====================================(*)
            #
            # - - -
            assert isinstance(item, fb.AdAccount)
            attrs = item.export_all_data()
SlavaSkvortsov commented 4 years ago

The quick fix is to use 7.0.3 :)

aljinovic commented 4 years ago

Pagination is still not fixed, is there a reason why this can't be merged, it looks like an obvious bug?

ppleskov commented 4 years ago

pls merge :)

pradeepadi88 commented 4 years ago

can you please merge this change?

AydarAkhmetzyanov commented 4 years ago

Could you please merge this ASAP, wondering how 8.0 was published with broken pagination.

CheckMaks commented 4 years ago

can you please merge this change?

maxexcloo commented 4 years ago

Could this be merged please?

nicholricc commented 3 years ago

can this be merged in? any idea what's causing the delay?

brandonkane commented 3 years ago

This should be closed, the fix is already in master: https://github.com/facebook/facebook-python-business-sdk/commit/422d88aeb8e057b92820b430c1006964c1ae887f

If you look at the file diff on this PR there are no changes left, after SlavaSkvortsov rebased it to master a couple days ago there is nothing left to merge.

AydarAkhmetzyanov commented 3 years ago

This should be closed, the fix is already in master: 422d88a

If you look at the file diff on this PR there are no changes left, after SlavaSkvortsov rebased it to master a couple days ago there is nothing left to merge.

Good. But it is a critical bug and fix is not yet released as a new version for pip.

jingping2015 commented 3 years ago

Since v8.0.2, this bug should be fixed.