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

Uploading assets to a release breaks the Repository object #779

Closed
iliapolo opened this issue May 1, 2018 · 12 comments
Closed

Uploading assets to a release breaks the Repository object #779

iliapolo opened this issue May 1, 2018 · 12 comments

Comments

@iliapolo
Copy link

iliapolo commented May 1, 2018

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

@iliapolo
Copy link
Author

iliapolo commented May 1, 2018

Forgot to mention my env:

Python 2.7.14
MacOS High Sierra
PyGithub 1.38

@mfonville
Copy link
Contributor

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

@iliapolo
Copy link
Author

iliapolo commented May 2, 2018

Awesome

Thanks 👍

@sfdye
Copy link
Member

sfdye commented May 4, 2018

Yes, will try to get #771 merged soon.

@YakDriver
Copy link
Contributor

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

@YakDriver
Copy link
Contributor

YakDriver commented May 31, 2018

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

@nurupo
Copy link
Contributor

nurupo commented Jun 25, 2018

Should be resolved now that #771 is merged?

@sfdye
Copy link
Member

sfdye commented Jun 25, 2018 via email

@sfdye sfdye closed this as completed Jun 25, 2018
@sfdye sfdye reopened this Jun 25, 2018
@sfdye
Copy link
Member

sfdye commented Jun 25, 2018

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

@iliapolo
Copy link
Author

@sfdye on it

@iliapolo
Copy link
Author

@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 :))

@sfdye
Copy link
Member

sfdye commented Jun 27, 2018

@iliapolo Cool, will take a look.

@sfdye sfdye closed this as completed Jun 27, 2018
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

No branches or pull requests

5 participants