MediaMath / t1-python

Python SDK for MediaMath Platform APIs
https://developer.mediamath.com/
Apache License 2.0
18 stars 30 forks source link

Add conditionals to determine if GET request is for a collection #87

Closed Cawb07 closed 8 years ago

conoverm commented 8 years ago

This is blocking a BSE release.

Cawb07 commented 8 years ago

@pswaminathan After investigating a related cron error, I'm seeing another case that would be fixed by this:

for campaign in campaigns:
    _, count = t1.get('strategies', limit={'campaign': campaign.id}, count=True, page_limit=1)

In cases where the campaign only has one strategy, count == 1, so not only do we not return a generator for the collection requested, but count is also not returned causing an AttributeError: 0.

pswaminathan commented 8 years ago

Ah I see. So really what we should do isn't to force an ent_count in any direction, or to check a bunch of different things. What we should really do is to see if the object passed in is an iterator and go from there. I'm playing around with it.

Cawb07 commented 8 years ago

@pswaminathan just fleshed out the "check a bunch of different things" solution. Realized user can still pass count=True when they're not requesting a collection and that would also cause an AttributeError.

pswaminathan commented 8 years ago

Sorry—what I'm saying is that I don't like having the check a bunch of things solution. I'm figuring out a way to refactor accordingly.