[Fix] ops.models.adhoc (#4096)

pull/4098/head
xinwen 2020-06-11 20:30:59 +08:00 committed by GitHub
parent 4b2fd0d0da
commit b14ca14120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 5 deletions

View File

@ -128,12 +128,14 @@ class Task(PeriodTaskModelMixin, OrgModelMixin):
def _last_adhocexecution(self, is_success, key): def _last_adhocexecution(self, is_success, key):
obj = AdHocExecution.objects.filter(task_id=self.id, is_success=is_success).order_by('-date_finished').first() obj = AdHocExecution.objects.filter(task_id=self.id, is_success=is_success).order_by('-date_finished').first()
body = obj.summary.get(key) body = obj.summary and obj.summary.get(key)
if body: if body:
asset, body = body.popitem() asset, body = body.popitem()
if body:
action, body = body.popitem() action, body = body.popitem()
return asset, action, body.get('msg', '') return asset, action, (body or '') and body.get('msg', '')
else: return asset, '', ''
return '', '', '' return '', '', ''
def __str__(self): def __str__(self):