Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor's skip setting is lost after an iteration on the cursor #41

Open
shnups opened this issue Oct 21, 2019 · 0 comments
Open

Cursor's skip setting is lost after an iteration on the cursor #41

shnups opened this issue Oct 21, 2019 · 0 comments

Comments

@shnups
Copy link
Member

shnups commented Oct 21, 2019

Using the following code snippet:

import logging

from appnexus import Campaign, connect

logging.basicConfig()
logging.getLogger("appnexus-client").setLevel(logging.DEBUG)

connect('XXXXXXXXXX', 'XXXXXXXXXX')

def gather(cursor):
    print("----------")
    print("Cursor.before:\tskip={}, limit={}".format(cursor._skip, cursor._limit))

    results = [res for res in cursor]   

    print("Results:\t{}".format(len(results)))
    print("Cursor.after:\tskip={}, limit={}".format(cursor._skip, cursor._limit))

cursor = Campaign.find(advertiser_id=XXXXXXXXXX)
cursor.skip(10)
gather(cursor)

The following will be outputted (authentication-related logs redacted):

----------
Cursor.before:  skip=100, limit=inf
DEBUG:appnexus-client:{'Authorization': 'XXXXXXXXXX'} https://api.appnexus.com/campaign?advertiser_id=XXXXXXXXXX&start_element=0&num_elements=1 None
DEBUG:appnexus-client:{'Authorization': 'XXXXXXXXXX'} https://api.appnexus.com/campaign?advertiser_id=XXXXXXXXXX&start_element=0&num_elements=100 None
DEBUG:appnexus-client:{'Authorization': 'XXXXXXXXXX'} https://api.appnexus.com/campaign?advertiser_id=XXXXXXXXXX&start_element=100&num_elements=100 None
DEBUG:appnexus-client:{'Authorization': 'XXXXXXXXXX'} https://api.appnexus.com/campaign?advertiser_id=XXXXXXXXXX&start_element=200&num_elements=100 None
Results:        128
Cursor.after:   skip=0, limit=inf
----------
Cursor.before:  skip=0, limit=inf
DEBUG:appnexus-client:{'Authorization': 'XXXXXXXXXX'} https://api.appnexus.com/campaign?advertiser_id=XXXXXXXXXX&start_element=0&num_elements=1 None
DEBUG:appnexus-client:{'Authorization': 'XXXXXXXXXX'} https://api.appnexus.com/campaign?advertiser_id=XXXXXXXXXX&start_element=0&num_elements=100 None
DEBUG:appnexus-client:{'Authorization': 'XXXXXXXXXX'} https://api.appnexus.com/campaign?advertiser_id=XXXXXXXXXX&start_element=100&num_elements=100 None
DEBUG:appnexus-client:{'Authorization': 'XXXXXXXXXX'} https://api.appnexus.com/campaign?advertiser_id=XXXXXXXXXX&start_element=200&num_elements=100 None
Results:        228
Cursor.after:   skip=0, limit=inf

I believe that a value to skip should be set once and maintain during the lifetime of the cursor instance, or at least until it is set again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant