Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'NoneType' object is not subscriptable #322

Closed
gilberthl-mh opened this issue Jun 19, 2024 · 12 comments · Fixed by #325
Closed

TypeError: 'NoneType' object is not subscriptable #322

gilberthl-mh opened this issue Jun 19, 2024 · 12 comments · Fixed by #325
Assignees
Labels
bug Something isn't working

Comments

@gilberthl-mh
Copy link

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

@gilberthl-mh gilberthl-mh added the bug Something isn't working label Jun 19, 2024
@zkoppert
Copy link
Member

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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

@zkoppert
Copy link
Member

Thanks @gilberthl-mh ! Appreciate the collaboration!!

@zkoppert zkoppert self-assigned this Jun 20, 2024
@jmeridth
Copy link
Member

jmeridth commented Jun 20, 2024

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

@zkoppert possibly related sigmavirus24/github3.py#988

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

@gilberthl-mh
Copy link
Author

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
Copy link
Member

@gilberthl-mh Check out #325. That should allow us to catch this error and continue on instead of terminating the actions run.

@gilberthl-mh
Copy link
Author

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
Copy link
Member

Thanks for the update! I've added #326 to address. Definitely let me know if anything else comes up!

@gilberthl-mh
Copy link
Author

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

@zkoppert
Copy link
Member

Glad to hear it!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants