Pygithub: Uploading assets to a release breaks the Repository object

Created on 1 May 2018  ·  12Comments  ·  Source: PyGithub/PyGithub

I am seeing some really strange behaviour after using the GitRelease object to upload an asset to a release.

Case in point:

import os
from github import Github

repo = Github(os.environ['GITHUB_ACCESS_TOKEN']).get_repo('<my-repo>')
release = repo.get_release(id='1.0.0')

repo.get_branch(branch='release')  # works

release.upload_asset(path='/Users/elip/asset', content_type='application/octet-stream')

repo.get_branch(branch='release')  # throws the exception

Exception:

Traceback (most recent call last):
  File "pygithub_bug.py", line 16, in <module>
    repo.get_branch(branch='release')
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Repository.py", line 1191, in get_branch
    self.url + "/branches/" + branch
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 185, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 198, in __check
    raise self.__createException(status, responseHeaders, output)
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 210, in __createException
    elif status == 404 and output.get("message") == "Not Found":
AttributeError: 'NoneType' object has no attribute 'get'

Worth mentioning that its not just the get_branch that breaks, every single method that needs to fetch something from Github fails with this error.

Also worth mentioning, is that sometimes, the exception is different:

Traceback (most recent call last):
  File "pygithub_bug.py", line 19, in <module>
    repo.get_commit(sha='release')
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Repository.py", line 1267, in get_commit
    self.url + "/commits/" + sha
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 185, in requestJsonAndCheck
    return self.__check(*self.requestJson(verb, url, parameters, headers, input, cnx))
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 231, in requestJson
    return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 275, in __requestEncode
    url = self.__makeAbsoluteUrl(url)
  File "/Users/elip/.virtualenvs/pyci/lib/python2.7/site-packages/github/Requester.py", line 343, in __makeAbsoluteUrl
    assert o.hostname in [self.__hostname, "uploads.github.com"], o.hostname
AssertionError: api.github.com

This exception happens, when i add repo.default_branch (or i assume any property invocation that requires a REST call) just before i upload.

Can someone shed some light? am i missing something here?

thanks

All 12 comments

Forgot to mention my env:

Python 2.7.14
MacOS High Sierra
PyGithub 1.38

This is a known problem, see my PR #771 that will resolve this bug, it will be merged by the dev for next release

Awesome

Thanks 👍

Yes, will try to get #771 merged soon.

Would love to see this merged. Running into the same problem.

The workaround I use for this is pretty easy. Basically after every file upload, I just recreate the github, repo, and release instances. Here's the pseudocode (full code is in Satsuki):

try:
  release_asset = release.upload_asset (
    path,
    **args
  )
except Exception as e:
  error = e
finally:
  gh = github.Github(...)
  repo = gh.get_repo(...)
  release = repo.get_release(...)

# see if e is an actual error, usually it's not

Should be resolved now that https://github.com/PyGithub/PyGithub/pull/771 is merged?

Yes


From: nurupo notifications@github.com
Sent: Monday, June 25, 2018 2:32:26 PM
To: PyGithub/PyGithub
Cc: Wan Liuyang; Comment
Subject: Re: [PyGithub/PyGithub] Uploading assets to a release breaks the Repository object (#779)

Should be resolved by #771https://github.com/PyGithub/PyGithub/pull/771 being merged?


You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/PyGithub/PyGithub/issues/779#issuecomment-399846062, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AA-CRnGC3DneR2a5__s9jFIwPiPraMrFks5uAIP6gaJpZM4Tt_wu.

It should be fixed by #771 . Can you guys try the the master? I will probably cut a release soon.

@sfdye on it

@sfdye looks good 👍 , thanks!

BTW, im not sure how you cut releases, but you can have a look at a tool I wrote specifically for managing releases for Python projects hosted on GIthub. Its called pyci, maybe you can benefit from it... (Sorry for the shameless plug, but it seemed appropriate :))

@iliapolo Cool, will take a look.

Was this page helpful?
0 / 5 - 0 ratings