Skip to content

Conversation

@ricardofontanelli
Copy link
Contributor

@ricardofontanelli ricardofontanelli commented Oct 21, 2022

The item_iterator method uses a query parameter called since to get the next results from the API resource when the previous response includes a hasMore=True property.

The problem here is the last API call leaves the query parameter defined to a value related to the previous resource retrieved, and if you use the same api client to iterate over different resources (i.e. campaigns), the results will always be affected by the previous call.

In the case below, since the api variable is defined outside the loop (as expected), responses for campaign 22222 will be affected by the since property from the last call to campaign 11111 resulting in fewer responses or, in many cases, empty result.

Example:

campaign_id_list = ['11111', '22222']
all_responses = []
api = ub.APIClient('my-client-key', 'my-secret-key')

for campaign_id in campaign_id_list:
    campaign_responses = api.get_resource(api.SCOPE_LIVE, api.PRODUCT_WEBSITES, api.RESOURCE_CAMPAIGN_RESULT, campaign_id, iterate=True)

    campaign_responses = [item['id'] for item in campaign_responses]
    all_responses += campaign_responses

print(len(all_responses))

It's probably the same issue reported here.

@ricardofontanelli ricardofontanelli force-pushed the bugfix/item_iterator-reset-query-parameters-after-returning-all-items branch from adf106f to 9c174a3 Compare October 21, 2022 11:54
@ricardofontanelli ricardofontanelli linked an issue Oct 21, 2022 that may be closed by this pull request
@ricardofontanelli ricardofontanelli added this to the v2.1.0 milestone Oct 21, 2022
@ricardofontanelli ricardofontanelli force-pushed the bugfix/item_iterator-reset-query-parameters-after-returning-all-items branch from 9c174a3 to 1517b4d Compare October 21, 2022 16:15
…items

The item_iterator method uses a query parameter called `since` to get the next
results from the API resource when the previous response includes a hasMore=True
property.

The problem here is the last API call leaves the query parameter defined to a
value related to the previous resource retrieved, and if you use the same api
client to iterate over different resources (i.e. campaigns), the results will
always be affected by the previous call.
@ricardofontanelli ricardofontanelli force-pushed the bugfix/item_iterator-reset-query-parameters-after-returning-all-items branch from 1517b4d to d8ff5eb Compare October 24, 2022 09:53
@ricardofontanelli ricardofontanelli merged commit 0a66560 into master Oct 26, 2022
@ricardofontanelli ricardofontanelli modified the milestones: v2.1.0, v2.0.2 Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Results are not idem-potents

2 participants