Closed Cawb07 closed 8 years ago
Also, this PR wouldn't fix another issue where the user doesn't know what type of object they're receiving from T1Service. It's actually happening to me right now with the code currently in production, where for these:
day_parts = t1.get('strategies', _id, child='day_parts')
concepts = t1.get('strategies', _id, child='concepts')
I have to check if I'm receiving a generator. Also when I try to force receiving a generator, this appears to be broken:
>>> generator = t1.get('strategies', 683880, 'concepts', get_all=True)
>>> for item in generator: print item
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/terminalone/service.py", line 487, in _get_all
for item in gen:
File "/Library/Python/2.7/site-packages/terminalone/entity.py", line 66, in __getitem__
raise AttributeError(attribute)
AttributeError: 0
@Cawb07 can you rebase this on master? I'm having trouble seeing what is new and what isn't.
@pswaminathan did git rebase master
from child-generator branch
pswaminathan at mm-mac-3325 in ~
$ adama "$APIBASE/strategies/151940/concepts"
<?xml version='1.0' ?>
<result called_on="2016-03-09 19:36:37.024292+00">
<entities count="1" start="0">
<entity name="GM Test" id="140139" type="concept" version="0">
<prop name="advertiser_id" value="105162" />
<prop name="name" value="GM Test" />
<prop name="status" value="1" />
<prop name="created_on" value="2012-09-27T15:47:47" />
<prop name="updated_on" value="2012-09-27T15:47:47" />
</entity>
</entities>
<status code="ok" />
</result>
pswaminathan at mm-mac-3325 in ~
$ adamj "$APIBASE/strategies/151940/concepts"
{
"data" : [
{
"advertiser_id" : 105162,
"created_on" : "2012-09-27T15:47:47+0000",
"status" : true,
"version" : 0,
"entity_type" : "concept",
"name" : "GM Test",
"id" : 140139,
"updated_on" : "2012-09-27T15:47:47+0000"
}
],
"meta" : {
"etag" : "0d1d83c7e37720985e0321c1f91e2a015ccb2178",
"count" : 1,
"called_on" : "2016-03-09T19:38:54+0000",
"status" : "ok",
"offset" : 0,
"total_count" : 1
}
}
This is a collection being requested.
>>> t = t1.get('strategies', 151940, child='concepts')
>>> t
Concept(status=True, _type='concept', name='GM Test', parent='strategies', advertiser_id=105162, parent_id=151940, created_on=datetime.datetime(2012, 9, 27, 15, 47, 47, tzinfo=FixedOffset(0)), version=0, updated_on=datetime.datetime(2012, 9, 27, 15, 47, 47, tzinfo=FixedOffset(0)), id=140139)
This should return a generator, not a single entity.
Also, this PR wouldn't fix another issue where the user doesn't know what type of object they're receiving from T1Service. It's actually happening to me right now with the code currently in production, where for these: (child='concepts' and child='day_parts')
Shouldn't these always return generators? If you don't know if something is multiple or one, it should return a generator. An entity is an entity. Requesting something without an entity (in this case, the child is really being requested, not the entity's ID) is a collection and should return a generator.
Ah sorry about the child collection (facepalm). Will fix now.
I think the tests were written expecting requests for single entities to return an iterator.