sigmavirus24 / github3.py

Hi, I'm a library for interacting with GItHub's REST API in a convenient and ergonomic way. I work on Python 3.6+.
https://github3.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.21k stars 402 forks source link

fix: improve handling deleted GH users #1161

Open caugner opened 1 year ago

caugner commented 1 year ago

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 https://github.com/sigmavirus24/github3.py/issues/988.

Version Information

Please provide:

Minimum Reproducible Example

n/a

Exception information

n/a

caugner commented 1 year ago

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

caugner commented 1 year ago

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.

sigmavirus24 commented 1 year ago

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 commented 9 months ago

@caugner are you still interested in implementing a GhostUser?