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 is not taken into account at both the url and output levels #43

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

Comments

@shnups
Copy link
Member

shnups commented Oct 21, 2019

To demonstrate the behavior, consider the code below:

import logging

from appnexus import Campaign, connect

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

connect('XXXXXXXXXX, 'XXXXXXXXXX')

def gather(cursor):
    print("Cursor.before:\tskip={}, limit={}".format(cursor._skip, cursor._limit))
    results = [res for res in cursor]   
    print("Results ({}):\t{}".format(len(results), ','.join([str(r.id) for r in results])))
    print("Cursor.after:\tskip={}, limit={}".format(cursor._skip, cursor._limit))

In a case without setting a value for skip (targeting a query that results 230 results normally):

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

The output will be:

Cursor.before:  skip=0, limit=10
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
Results (10):   100001,100002,100003,100004,100005,100006,100007,100008,100009,100010
Cursor.after:   skip=0, limit=10

In a case with a skip value:

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

The output will be the same:

Cursor.before:  skip=0, limit=10
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
Results (10):   100001,100002,100003,100004,100005,100006,100007,100008,100009,100010
Cursor.after:   skip=0, limit=10

We can observe that:

  1. The skip argument is not taken into account in the url we target (as the start_element field) and therefore skip number of results are obtained while we'll have no use for them later on
  2. Whether or not the skip is set on the cursor, the user will still get the results he/she was trying to skip.

PS: Here, two separate scripts/runs are necessary, otherwise no output at all will be gathered the second time around because of issue #42

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