NoneType issue when calling `_update_attributes` in `users`
travishathaway opened this issue · 2 comments
travishathaway commented
Traceback:
Traceback (most recent call last):
File "/Users/computeruser/dev/issue-metrics/issue_metrics.py", line 327, in <module>
main()
File "/Users/computeruser/dev/issue-metrics/issue_metrics.py", line 282, in main
issues_with_metrics, num_issues_open, num_issues_closed = get_per_issue_metrics(
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/computeruser/dev/issue-metrics/issue_metrics.py", line 184, in get_per_issue_metrics
issue_with_metrics.label_metrics = get_label_metrics(issue, labels)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/computeruser/dev/issue-metrics/labels.py", line 45, in get_label_metrics
label_events = get_label_events(issue, labels)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/computeruser/dev/issue-metrics/labels.py", line 26, in get_label_events
for event in issue.issue.events():
File "/Users/computeruser/micromamba/envs/issue-metrics/lib/python3.11/site-packages/github3/structs.py", line 131, in __iter__
yield cls(i)
^^^^^^
File "/Users/computeruser/micromamba/envs/issue-metrics/lib/python3.11/site-packages/github3/models.py", line 52, in __init__
self._update_attributes(json)
File "/Users/computeruser/micromamba/envs/issue-metrics/lib/python3.11/site-packages/github3/issues/event.py", line 63, in _update_attributes
self.actor = users.ShortUser(event["actor"], self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/computeruser/micromamba/envs/issue-metrics/lib/python3.11/site-packages/github3/models.py", line 52, in __init__
self._update_attributes(json)
File "/Users/computeruser/micromamba/envs/issue-metrics/lib/python3.11/site-packages/github3/users.py", line 309, in _update_attributes
self.avatar_url = user["avatar_url"]
~~~~^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
adding this to _update_attributes
seems to have resolved this issue:
def _update_attributes(self, user):
if user is not None:
self.avatar_url = user["avatar_url"]
self.events_urlt = URITemplate(user["events_url"])
self.followers_url = user["followers_url"]
self.following_urlt = URITemplate(user["following_url"])
self.gists_urlt = URITemplate(user["gists_url"])
self.gravatar_id = user["gravatar_id"]
self.html_url = user["html_url"]
self.id = user["id"]
self.login = user["login"]
self.organizations_url = user["organizations_url"]
self.received_events_url = user["received_events_url"]
self.repos_url = user["repos_url"]
self.site_admin = user.get("site_admin")
self.starred_urlt = URITemplate(user["starred_url"])
self.subscriptions_url = user["subscriptions_url"]
self.type = user["type"]
self.url = self._api = user["url"]
self._uniq = self.id
travishathaway commented
I ran across this while using this project:
sigmavirus24 commented
#1161 or something like it would fix this nicely if you're interested in sending a PR