From 1d6b7883b30c74f77475b9330f7283d432532579 Mon Sep 17 00:00:00 2001 From: GunChleoc Date: Sun, 8 Sep 2019 16:16:43 +0100 Subject: [PATCH] Prevent crashes if an owner's account has been suspended on Launchpad --- lp2gh/bugs.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lp2gh/bugs.py b/lp2gh/bugs.py index 9bf9d0d..18795ec 100644 --- a/lp2gh/bugs.py +++ b/lp2gh/bugs.py @@ -58,8 +58,14 @@ def message_to_dict(message): - owner = message.owner - return {'owner': owner.name, + # We skip errors caused by suspended users + try: + owner = message.owner + owner_name = owner.name or "unknown" + except: + owner_name = "unknown" + + return {'owner': owner_name, 'content': message.content, 'date_created': util.to_timestamp(message.date_created), } @@ -67,8 +73,19 @@ def message_to_dict(message): def bug_task_to_dict(bug_task): bug = bug_task.bug - assignee = bug_task.assignee - owner = bug_task.owner + + # We skip errors caused by suspended users + try: + assignee = bug_task.assignee + assignee_name = assignee.name or None, + except: + assignee_name = None + try: + owner = bug_task.owner + owner_name = owner.name or "unknown" + except: + owner_name = "unknown" + messages = list(bug.messages)[1:] milestone = bug_task.milestone duplicates = bug.duplicates @@ -77,7 +94,7 @@ def bug_task_to_dict(bug_task): 'status': bug_task.status, 'importance': bug_task.importance, 'assignee': assignee and assignee.name or None, - 'owner': owner.name, + 'owner': owner_name, 'milestone': milestone and milestone.name, 'title': bug.title, 'description': bug.description,