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

fix: improve handling deleted GH users #1161

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

caugner
Copy link

@caugner caugner commented Sep 19, 2023

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

Fixes #988.

Version Information

Please provide:

  • The version of Python you're using: 3.11.5
  • The version of pip you used to install github3.py: 23.2.1
  • The version of github3.py (4.0.1), requests (2.31.0), uritemplate (?), and dateutil (?) installed:

Minimum Reproducible Example

n/a

Exception information

n/a

@caugner
Copy link
Author

caugner commented Sep 19, 2023

Hi @sigmavirus24, could you please approve the workflows? 🙏

@caugner caugner marked this pull request as draft September 19, 2023 16:35
Copy link
Owner

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't default to None of I remember correctly. People will instead have an Attribute Error trying to access something that otherwise is there

@caugner
Copy link
Author

caugner commented Sep 21, 2023

This won't default to None of I remember correctly. People will instead have an Attribute Error trying to access something that otherwise is there

I'm not sure I understand. Are you saying that this won't help, because people will get a different Error when accessing a property on event.actor without checking event.actor first? I would argue this is still better than before, because users currently cannot do anything against github3 running into this TypeError as soon as they encounter an event by a deleted user (except monkey-patching maybe).

I guess an alternative would be to initialize a GhostUser object instead, as if https://github.com/ghost was a real user.

PS: The failing Python 3.9/3.10 tests seem unrelated.

@caugner caugner marked this pull request as ready for review September 21, 2023 09:56
src/github3/events.py Outdated Show resolved Hide resolved
@caugner caugner changed the title fix(events): init EventUser only if actor is defined fix(events): handle event["actor"] == None Sep 22, 2023
@caugner caugner changed the title fix(events): handle event["actor"] == None fix: improve handling deleted GH users Sep 29, 2023
@sigmavirus24
Copy link
Owner

I guess an alternative would be to initialize a GhostUser object instead, as if https://github.com/ghost was a real user.

The more I think about it, the more I like the idea of a GhostUser object or a Ghost sentinel that we can return.

@sigmavirus24
Copy link
Owner

@caugner are you still interested in implementing a GhostUser?

caugner and others added 6 commits December 15, 2023 08:43
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
```
`owner` is null if the user who opened the PR
no longer exists on GitHub.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: 'NoneType' object is not subscriptable
2 participants