Commit df37a4d1 authored by Nicola Spanti's avatar Nicola Spanti
Browse files

[py] Manage case `result.info` is an exception

In a client project, we add the case of `result.info` being
`UException` (from `cubicweb_nemo.utils`). It resulted in a
problem, because `result.info` is `True` as boolean, but it has
no key, so it crashed. This patch does not resolve the real
problem of having a clean `info` member or knowing why it could
normally have a different type, but at least it eliminates a
problem for the final users.
parent 256d437ec4d9
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# details. # details.
# #
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
"""cubicweb-celerytask entity's classes""" """cubicweb-celerytask entity's classes"""
import six import six
...@@ -204,16 +204,18 @@ class ICeleryTask(EntityAdapter): ...@@ -204,16 +204,18 @@ class ICeleryTask(EntityAdapter):
if celery.current_app.conf.task_always_eager: if celery.current_app.conf.task_always_eager:
return 1. return 1.
result = self.result result = self.result
if result.info and 'progress' in result.info: try:
return result.info['progress'] if result.info and 'progress' in result.info:
elif self.entity.reverse_parent_task: return result.info['progress']
except TypeError:
pass
if self.entity.reverse_parent_task:
children = self.entity.reverse_parent_task children = self.entity.reverse_parent_task
return sum(child.cw_adapt_to('ICeleryTask').progress return sum(child.cw_adapt_to('ICeleryTask').progress
for child in children) / len(children) for child in children) / len(children)
elif result.state == STATES.SUCCESS: if result.state == STATES.SUCCESS:
return 1. return 1.
else: return 0.
return 0.
@property @property
def state(self): def state(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment