Skip to content

Commit 17a46e3

Browse files
caugnersigmavirus24
authored andcommitted
fix(events): init EventUser only if actor is defined
Prevents the following TypeError with events of deleted users (aka "ghost"): ``` File "/path/to/github3/models.py", line 52, in __init__ self._update_attributes(json) File "/path/to/github3/issues/event.py", line 63, in _update_attributes self.actor = users.ShortUser(event["actor"], self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/github3/models.py", line 52, in __init__ self._update_attributes(json) File "/path/to/github3/users.py", line 309, in _update_attributes self.avatar_url = user["avatar_url"] TypeError: 'NoneType' object is not subscriptable ```
1 parent 03d4bc5 commit 17a46e3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/github3/events.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ class Event(models.GitHubCore):
392392
.. attribute:: actor
393393
394394
A :class:`~github3.events.EventUser` that represents the user whose
395-
action generated this event.
395+
action generated this event, or `None` if the user no longer exists.
396396
397397
.. attribute:: created_at
398398
@@ -442,7 +442,8 @@ def _update_attributes(self, event):
442442
# If we don't copy this, then we end up altering _json_data which we do
443443
# not want to do:
444444
event = copy.deepcopy(event)
445-
self.actor = EventUser(event["actor"], self)
445+
if event["actor"]:
446+
self.actor = EventUser(event["actor"], self)
446447
self.created_at = self._strptime(event["created_at"])
447448
self.id = event["id"]
448449
self.org = event.get("org")

0 commit comments

Comments
 (0)