sbg / sevenbridges-python

SevenBridges Python Api bindings
Apache License 2.0
46 stars 27 forks source link

Batch task get_execution_details().jobs results in TypeError #39

Closed ghost closed 8 years ago

ghost commented 8 years ago

Steps to replicate

  1. Start a batch task
  2. Get execution details
  3. Retrieve jobs attribute
  4. TypeError results

An example with an existing task is as follows

bt = api.tasks.get(id='f198c7a8-f246-48fc-b335-298fa64de0d3')    #  A completed batch task
bt.get_execution_details().jobs
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-569-c9cbeaba8660> in <module>()
----> 1 bt.get_execution_details().jobs

/Users/kghose/miniconda2/envs/bench/lib/python2.7/site-packages/sevenbridges/meta/fields.pyc in __get__(self, instance, owner)
     80     def __get__(self, instance, owner):
     81         return [self.cls(api=instance._api, **item) for item in
---> 82                 instance._data[self.name]]
     83 
     84 

TypeError: 'NoneType' object is not iterable

This works fine with regular tasks. Thanks

SenadI commented 8 years ago

@kghosesbg Batch tasks do not have execution details. I will add an appropriate exception to be thrown when this call is invoked.

damirkrstanovic commented 8 years ago

The same thing happens when you wish to view task in draft state.

SenadI commented 8 years ago

@kghosesbg , @damirkrstanovic

The problem is not in the batch or the draft tasks itself. The issue is in the logic. This will happen anytime you access the task that has 0 produced jobs. The job list is empty, and the CompoundListFiled class will throw an error. It throws an error because it tries to create a list resource by using list comprehension and the there are no items. I will fix this by returning empty list if there no present jobs in task. This will fix the issue of NoneType error and the necessity to catch errors as they happen.

SenadI commented 8 years ago

Fixed. Will return empty list when jobs are None.