appnexus-client icon indicating copy to clipboard operation
appnexus-client copied to clipboard

Cursor's skip is not taken into account at both the url and output levels

Open shnups opened this issue 6 years ago • 0 comments

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

shnups avatar Oct 21 '19 15:10 shnups