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 gist.history keyerrors #1020

Merged
merged 2 commits into from Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/source/release-notes/2.0.0.rst
@@ -1,4 +1,4 @@
2.0.0: 2020-01-06
2.0.0: 2020-01-10
-----------------

Features Added
Expand All @@ -10,6 +10,11 @@ Features Added
- Remove compatibility imports for Python 2.
- Remove dev-dependency for mock.

Bugs Fixed
``````````

* Key errors on Gist.history.

Removals
````````

Expand Down Expand Up @@ -56,4 +61,3 @@ Removals
- ``Organization#add_member`` add ``username`` to ``team``.
- ``Organization#events`` use ``Organization#public_events``
- ``Issue#assign`` use ``issues.issue.Issue.add_assignees``

20 changes: 10 additions & 10 deletions src/github3/gists/history.py
Expand Up @@ -43,24 +43,24 @@ class GistHistory(models.GitHubCore):
The number of deletions from the gist compared to the previous
revision.

.. attribute:: totoal
.. attribute:: total

The total number of changes to the gist compared to the previous
revision.
"""

def _update_attributes(self, history):
def _update_attributes(self, history) -> None:
self.url = self._api = history["url"]
self.version = history["version"]
self.user = users.ShortUser(history["user"], self)
self.change_status = history["change_status"]
self.additions = self.change_status["additions"]
self.deletions = self.change_status["deletions"]
self.total = self.change_status["total"]
self.committed_at = self._strptime(history["committed_at"])

def _repr(self):
return "<Gist History [{0}]>".format(self.version)
self.change_status = history.get("change_status")
self.additions = self.change_status.get("additions")
self.deletions = self.change_status.get("deletions")
self.total = self.change_status.get("total")
self.committed_at = self._strptime(history.get("committed_at"))

Copy link
Owner

Choose a reason for hiding this comment

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

This now makes it indistinguishable between GitHub returning null and the key being missing which semantically are two very different things.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

get() should be added then only to additions and deletions right?

Copy link
Owner

Choose a reason for hiding this comment

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

So missing data makes me think there's a way that GitHub represents the data that is different than the object we have here. (Think about ShortUser versus User versus AuthenticatedUser. There's different representations of the same object with different data. The history object here seems to have another representation. It seems like this happens when retrieving a single gist by its id (in the original issue). Given that used to work, that means GitHub's changed something and we probably need a different representation here (sadly).

Copy link
Owner

Choose a reason for hiding this comment

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

Personally, I'd love some kind of NotProvided singleton rather than this many objects but that proved confusing in the past

Copy link
Collaborator Author

@staticdev staticdev Jan 11, 2021

Choose a reason for hiding this comment

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

@sigmavirus24 I rolled back that changes for unnecessary fields. I am not really sure how to reproduce this other object representation and I don't have much knowledge of Github Gists. Could we use this PR as a hotfix to solve the user's problem and then we dig into this new structure in a new issue?

Copy link
Collaborator Author

@staticdev staticdev Jan 12, 2021

Choose a reason for hiding this comment

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

@sigmavirus24 also the user (on #1019) printed self.change_status before the error, the it is not quite another representation:

{'total': 2, 'additions': 1, 'deletions': 1}
{'total': 1, 'additions': 1, 'deletions': 0}
{'total': 4, 'additions': 2, 'deletions': 2}
{'total': 2, 'additions': 1, 'deletions': 1}
{'total': 1, 'additions': 1, 'deletions': 0}
{'total': 2, 'additions': 1, 'deletions': 1}
{'total': 3, 'additions': 2, 'deletions': 1}
{'total': 1, 'additions': 1, 'deletions': 0}
{'total': 4, 'additions': 2, 'deletions': 2}
{'total': 1, 'additions': 1, 'deletions': 0}
{}

def _repr(self) -> str:
return f"<Gist History [{self.version}]>"

def gist(self):
"""Retrieve the gist at this version.
Expand Down