PyGithub/PyGithub

Iterating through repo.get_tags() throws NoneType TypeError for repositories with lots of tags

erichaase opened this issue · 5 comments

For repositories with lots of tags (git, linux, etc.), iterating through repo.get_tags() throws a NoneType TypeError. Please see the following for the steps to recreate:

eric@white:~/autoport> pip freeze|ack pygithub
PyGithub==1.25.0

eric@white:~/autoport> python
Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from github import Github
>>> tags = Github("...").get_repo(2325298).get_tags()
>>> for tag in tags:
...     print tag
... 
<github.Tag.Tag object at 0xb6e1848c>
<github.Tag.Tag object at 0xb6e18e8c>
...
<github.Tag.Tag object at 0xb6d14b0c>
<github.Tag.Tag object at 0xb6d14c0c>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/github/PaginatedList.py", line 48, in __iter__
    newElements = self._grow()
  File "/usr/local/lib/python2.7/dist-packages/github/PaginatedList.py", line 60, in _grow
    newElements = self._fetchNextPage()
  File "/usr/local/lib/python2.7/dist-packages/github/PaginatedList.py", line 177, in _fetchNextPage
    for element in data
  File "/usr/local/lib/python2.7/dist-packages/github/GithubObject.py", line 74, in __init__
    self._storeAndUseAttributes(headers, attributes)
  File "/usr/local/lib/python2.7/dist-packages/github/GithubObject.py", line 86, in _storeAndUseAttributes
    self._useAttributes(attributes)
  File "/usr/local/lib/python2.7/dist-packages/github/Tag.py", line 73, in _useAttributes
    if "commit" in attributes:  # pragma no branch
TypeError: argument of type 'NoneType' is not iterable

Wow thanks for reporting that! I'll have a look in the coming days.

The issue comes from the GitHub API (see the nulls at the end):

curl https://api.github.com/repositories/2325298/tags?page=13

[
  {
    "name": "v2.6.15-rc7",
    "zipball_url": "https://api.github.com/repos/torvalds/linux/zipball/v2.6.15-rc7",
    "tarball_url": "https://api.github.com/repos/torvalds/linux/tarball/v2.6.15-rc7",
    "commit": {
      "sha": "f89f5948fc10bb973cd452d2e334da207828e228",
      "url": "https://api.github.com/repos/torvalds/linux/commits/f89f5948fc10bb973cd452d2e334da207828e228"
    }
  },
  {...........},
  {
    "name": "v2.6.12",
    "zipball_url": "https://api.github.com/repos/torvalds/linux/zipball/v2.6.12",
    "tarball_url": "https://api.github.com/repos/torvalds/linux/tarball/v2.6.12",
    "commit": {
      "sha": "9ee1c939d1cb936b1f98e8d81aeffab57bae46ab",
      "url": "https://api.github.com/repos/torvalds/linux/commits/9ee1c939d1cb936b1f98e8d81aeffab57bae46ab"
    }
  },
  null,
  null
]

I'll contact GitHub to see if they can fix it on their side. I'll also make a workaround in PyGithub.

Work-around in aadc286 and https://pypi.python.org/pypi/PyGithub/1.25.2

Thanks for reporting!

Response from Ivan Žužak (GitHub Support):

The team deployed some changes which should have resolved this issue. Let us know if you're still seeing null items in some responses, though.
Thanks again!

Great, thanks for the quick turnaround on this!