github3.py
github3.py copied to clipboard
branch.refresh() returns 404 if branch.name contains '#'
Version Information
python 3.6 pip 10.0.1 github3.py 1.1.0 requests 2.19.1 uritemplate 3.0.0 dateutil N/A
Minimum Reproducible Example
- Create a branch starts by '#'
- try to get branch.refresh()
- you will get:
Traceback (most recent call last): File "folder/main.py", line 43, in <module> out.write(''.join([resource_github_branch_protection(repo, branch) for branch in branches])) File "folder/main.py", line 43, in <listcomp> out.write(''.join([resource_github_branch_protection(repo, branch) for branch in branches])) File "folder/src/resources.py", line 81, in resource_github_branch_protection branch = branch.refresh() File "folder/venv/lib64/python3.6/site-packages/github3/models.py", line 300, in refresh json = self._json(self._get(self._api, headers=headers), 200) File "folder/venv/lib64/python3.6/site-packages/github3/models.py", line 156, in _json raise exceptions.error_for(response) github3.exceptions.NotFoundError: 404 Branch not found
I suspect that's any branch that has a # in it since # indicates the start of a "fragment" in RFC 3986. We don't tend to urlsafe the arguments as this isn't typically a problem. This is an interesting problem. This may be a fundamental change to make the handling smarter.
I just realized that branch.refresh() will use the URL returned by GitHub to perform the refresh. This means that we're getting back a URL that has the fragment not urlencoded for us. sigh