github / issue-metrics

Gather metrics on issues/prs/discussions such as time to first response, count of issues opened, closed, etc.
https://github.blog/2023-07-19-metrics-for-issues-pull-requests-and-discussions/
MIT License
372 stars 46 forks source link

TypeError: 'NoneType' object is not subscriptable #322

Closed gilberthl-mh closed 3 weeks ago

gilberthl-mh commented 1 month ago

Describe the bug

We have been running the issue-metrics action for a while now and it has been running without any issues, but just recently we've been receiving the error: TypeError: 'NoneType' object is not subscriptable

The full stack trace can be found below:

MH3-12587 add endpoint to delete single account
Traceback (most recent call last):
  File "/action/workspace/issue_metrics.py", line 433, in <module>
    main()
  File "/action/workspace/issue_metrics.py", line 367, in main
    issues_with_metrics, num_issues_open, num_issues_closed = get_per_issue_metrics(
                                                              ^^^^^^^^^^^^^^^^^^^^^^
  File "/action/workspace/issue_metrics.py", line 219, in get_per_issue_metrics
    ready_for_review_at = get_time_to_ready_for_review(issue, pull_request)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/action/workspace/time_to_ready_for_review.py", line 40, in get_time_to_ready_for_review
    for event in events:
  File "/usr/local/lib/python3.12/site-packages/github3/structs.py", line 131, in __iter__
    yield cls(i)
          ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/github3/models.py", line 52, in __init__
    self._update_attributes(json)
  File "/usr/local/lib/python3.12/site-packages/github3/issues/event.py", line 63, in _update_attributes
    self.actor = users.ShortUser(event["actor"], self)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/github3/models.py", line 52, in __init__
    self._update_attributes(json)
  File "/usr/local/lib/python3.12/site-packages/github3/users.py", line 309, in _update_attributes
    self.avatar_url = user["avatar_url"]
                      ~~~~^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

To Reproduce

I am unsure how best to reproduce this, I would need to find the PR that is causing this issue but I think the print issues is done fully before it gets to this code in the stack trace.

Expected behavior

Action to run to completion

Screenshots

No response

Additional context

No response

zkoppert commented 1 month ago

were you running this on an organization (github.com/org_name), list of repos (org/repository), or a personal namespace (zkoppert/repository)? Any other configuration options you can share?

gilberthl-mh commented 1 month ago

Apologies @zkoppert , that context would have been helpful!

We currently run the step with this config:

- name: Get issue metrics
  uses: github/issue-metrics@v3
  env:
    GH_TOKEN: ${{ steps.app-token.outputs.token }}
    HIDE_TIME_TO_ANSWER: true
    SEARCH_QUERY: "${{ steps.prod-repos.outputs.repos }} is:pr closed:${{ env.last_month }}"

The value ${{ steps.prod-repos.outputs.repos } evaluates to a space separated list of repo:moneyhub/${repo}

zkoppert commented 4 weeks ago

Theory: Maybe its possible that some repos have no events and so the events object is None and then we try to iterate over it (for event in events).

Yet another theory: There is no user attached to the event so when it tries to access user["avatar_url"] it doesn't exist because User is None.

I'll start investigating those. @jmeridth any thoughts on these or other theories?

gilberthl-mh commented 4 weeks ago

Thanks @zkoppert, I'll fork this repo and add some logs to run on our pipeline and see what is being caught out

zkoppert commented 4 weeks ago

Thanks @gilberthl-mh ! Appreciate the collaboration!!

jmeridth commented 4 weeks ago

I'll start investigating those. @jmeridth any thoughts on these or other theories?

@zkoppert possibly related https://github.com/sigmavirus24/github3.py/issues/988

Possible PR to fix already exists. Still deep diving to confirm.

gilberthl-mh commented 4 weeks ago

I have found the issue that it was failing on, and it was happening for a user that has since left our organisation (I think) and is noted as a "ghost".

See attached image

Screenshot 2024-06-20 at 19 49 52
zkoppert commented 3 weeks ago

@gilberthl-mh Check out https://github.com/github/issue-metrics/pull/325. That should allow us to catch this error and continue on instead of terminating the actions run.

gilberthl-mh commented 3 weeks ago

Thanks @zkoppert, that seems to bypass the above error. I think there's another instance where it's failing when looking at review comments for measure_time_to_first_response

An error occurred processing review events. Perhaps issue contains a ghost user. 'NoneType' object is not subscriptable
Traceback (most recent call last):
  File "/action/workspace/issue_metrics.py", line 436, in <module>
    main()
  File "/action/workspace/issue_metrics.py", line 370, in main
    issues_with_metrics, num_issues_open, num_issues_closed = get_per_issue_metrics(
                                                              ^^^^^^^^^^^^^^^^^^^^^^
  File "/action/workspace/issue_metrics.py", line 226, in get_per_issue_metrics
    measure_time_to_first_response(
  File "/action/workspace/time_to_first_response.py", line 76, in measure_time_to_first_response
    for review_comment in review_comments:
  File "/usr/local/lib/python3.12/site-packages/github3/structs.py", line 131, in __iter__
    yield cls(i)
          ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/github3/models.py", line 52, in __init__
    self._update_attributes(json)
  File "/usr/local/lib/python3.12/site-packages/github3/pulls.py", line 995, in _update_attributes
    self.user = users.ShortUser(review["user"], self)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/github3/models.py", line 52, in __init__
    self._update_attributes(json)
  File "/usr/local/lib/python3.12/site-packages/github3/users.py", line 309, in _update_attributes
    self.avatar_url = user["avatar_url"]
                      ~~~~^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
zkoppert commented 3 weeks ago

Thanks for the update! I've added https://github.com/github/issue-metrics/pull/326 to address. Definitely let me know if anything else comes up!

gilberthl-mh commented 3 weeks ago

Thank you very much @zkoppert, that has completely resolved the issue for us and we're able to run our action to completion 🙂

zkoppert commented 3 weeks ago

Glad to hear it!!