nbdev_release_git raises exception
nbdev_release_git triggers an error traceback referencing an HTTP exception. I am unsure how to proceed with debugging.
(test-release) tylere-macbookpro5:test-release tylere$ nbdev_release_git
Traceback (most recent call last):
File "/Users/tylere/miniconda3/envs/test-release/bin/nbdev_release_git", line 10, in <module>
sys.exit(release_git())
File "/Users/tylere/miniconda3/envs/test-release/lib/python3.10/site-packages/fastcore/script.py", line 119, in _f
return tfunc(**merge(args, args_from_prog(func, xtra)))
File "/Users/tylere/miniconda3/envs/test-release/lib/python3.10/site-packages/nbdev/release.py", line 117, in release_git
ver = Release(token=token).release()
File "/Users/tylere/miniconda3/envs/test-release/lib/python3.10/site-packages/nbdev/release.py", line 89, in release
self.gh.create_release(ver, branch=self.cfg.branch, body=notes)
File "/Users/tylere/miniconda3/envs/test-release/lib/python3.10/site-packages/ghapi/core.py", line 178, in create_release
rel = self.repos.create_release(tag_name, target_commitish=branch, name=name, body=body,
File "/Users/tylere/miniconda3/envs/test-release/lib/python3.10/site-packages/ghapi/core.py", line 61, in __call__
return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
File "/Users/tylere/miniconda3/envs/test-release/lib/python3.10/site-packages/ghapi/core.py", line 118, in __call__
res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=debug, return_headers=True,
File "/Users/tylere/miniconda3/envs/test-release/lib/python3.10/site-packages/fastcore/net.py", line 217, in urlsend
return urlread(req, return_json=return_json, return_headers=return_headers)
File "/Users/tylere/miniconda3/envs/test-release/lib/python3.10/site-packages/fastcore/net.py", line 118, in urlread
if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp, msg=e.msg) from None
Test repo: https://github.com/tylere/test-release
Steps to reproduce my local environment and trigger the error:
conda create -n test-release -c conda-forge -c fastai python=3.10 gh jupyterlab jupyterlab-git nbdev
source activate test-release
cd test-release
nbdev_new
nbdev_prepare
pip install -e '.[dev]'
nbdev preview
# save a GitHub token
echo ### > token
echo token >> .gitignore
nbdev_prepare
# Push changes to GitHub
git add .
git commit -m "Setup nbdev environment"
git push
# On GitHub, create an enhancement issue, then close it.
nbdev_changelog
git add CHANGELOG.md
git commit -m "Added changelog"
nbdev_release_git
We've added some better error reporting in ghapi and fastcore recently - could you grab the master versions of each and try again? Hopefully it'll at least tell you why there's a problem.
Generally this error occurs when there's an authentication problem FYI.
Yes, the master versions have a better error message, indicating that GH doesn't like the release tag.
I bumped the version number, but that didn't change the error. Am I missing a step?
(test-release-2) tylere-macbookpro5:test-release tylere$ nbdev_bump_version
Old version: 0.0.1
New version: 0.0.2
(test-release-2) tylere-macbookpro5:test-release tylere$ nbdev_changelog
(test-release-2) tylere-macbookpro5:test-release tylere$ nbdev_release_git
Traceback (most recent call last):
File "/Users/tylere/miniconda3/envs/test-release-2/bin/nbdev_release_git", line 33, in <module>
sys.exit(load_entry_point('nbdev', 'console_scripts', 'nbdev_release_git')())
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/script.py", line 119, in _f
return tfunc(**merge(args, args_from_prog(func, xtra)))
File "/Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py", line 117, in release_git
ver = Release(token=token).release()
File "/Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py", line 89, in release
self.gh.create_release(ver, branch=self.cfg.branch, body=notes)
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 180, in create_release
rel = self.repos.create_release(tag_name, target_commitish=branch, name=name, body=body,
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 61, in __call__
return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 120, in __call__
res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=debug, return_headers=True,
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/net.py", line 218, in urlsend
return urlread(req, return_json=return_json, return_headers=return_headers)
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/net.py", line 119, in urlread
if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp, msg=e.msg) from None
fastcore.net.HTTP422UnprocessableEntityError: HTTP Error 422: Unprocessable Entity
====Error Body====
{
"message": "Validation Failed",
"errors": [
{
"resource": "Release",
"code": "custom",
"field": "tag_name",
"message": "tag_name is not a valid tag"
},
{
"resource": "Release",
"code": "custom",
"message": "Published releases must have a valid tag"
},
{
"resource": "Release",
"code": "invalid",
"field": "target_commitish"
}
],
"documentation_url": "https://docs.github.com/rest/reference/repos#create-a-release"
}
Library versions
(test-release-2) tylere-macbookpro5:test-release tylere$ (cd ../../fastai/fastcore && git pull && git log -1)
Already up to date.
commit 0ee5b7f52a6b8d81691046d73555d56a25fbafac (HEAD -> master, origin/master, origin/HEAD)
Merge: f7e81b8 8fdfd81
Author: Jeremy Howard <[email protected]>
Date: Mon Sep 12 08:59:13 2022 +1000
Merge pull request #486 from seeM/fix-http-exceptions
fix: error in IPython while handling `HTTP4xxClientError`
(test-release-2) tylere-macbookpro5:test-release tylere$ (cd ../../fastai/ghapi && git pull && git log -1)
Already up to date.
commit 9dceb6c0d7a240bb2b936ea17acf36de698e645a (HEAD -> master, tag: 1.0.3, origin/master, origin/HEAD)
Author: Jeremy Howard <[email protected]>
Date: Tue Sep 13 12:26:00 2022 +1000
release
(test-release-2) tylere-macbookpro5:test-release tylere$ (cd ../../fastai/execnb && git pull && git log -1)
Already up to date.
commit 25f3a2f94eb0ea5b9c88303dfd6b9130caa7a029 (HEAD -> master, tag: 0.1.3, origin/master, origin/HEAD)
Author: Jeremy Howard <[email protected]>
Date: Sat Sep 3 13:13:53 2022 +1000
release
(test-release-2) tylere-macbookpro5:test-release tylere$ (cd ../../fastai/nbdev && git pull && git log -1)
Already up to date.
commit 9e559ad6985c16bfd09b2481b36bfdec285e9ca2 (HEAD -> master, origin/master, origin/HEAD)
Merge: f57e54e 5e79159
Author: Jeremy Howard <[email protected]>
Date: Wed Sep 14 16:09:37 2022 +1000
Merge pull request #1057 from seeM/fix-1032
set `output-file` using notebook filename instead of `default_exp`
Oh - it looks like you haven't created and pushed a commit for the release. Try git commit -am release then git push. Releases are tags, which are attached to commits. nbdev_release_gh does this for you btw.
Thanks for clarifying that.
However, I am getting the same error while using nbdev_release_gh so I am guessing I am still missing a prerequisite step.
To Reproduce
Test repo: https://github.com/tylere/test-release-3
Environment Setup
conda create -y -n test-release-3 -c conda-forge python=3.10 gh jupyterlab jupyterlab-git
source activate test-release-3
cd test-release-3
# Install fastai dependencies and display versions
pip install -e ../../fastai/fastcore/
pip install -e ../../fastai/ghapi/
pip install -e ../../fastai/execnb/
pip install -e ../../fastai/nbdev/
(cd ../../fastai/fastcore && git pull && git log -1)
(cd ../../fastai/ghapi && git pull && git log -1)
(cd ../../fastai/execnb && git pull && git log -1)
(cd ../../fastai/nbdev && git pull && git log -1)
pip install -e '.[dev]'
nbdev_new
# save a GitHub token
echo ### > token
echo token >> .gitignore
# Push changes to GitHub
nbdev_prepare
git add .
git commit -m "Setup nbdev environment"
git push
Triggering the error:
(test-release-3) tylere-macbookpro5:test-release-3 tylere$ git commit -m "Fixes #1"
[main 16f0a46] Fixes #1
1 file changed, 9 insertions(+)
(test-release-3) tylere-macbookpro5:test-release-3 tylere$ nbdev_release_gh
Make release now? (y/n) y
Username for 'https://github.com': tylere
Password for 'https://[email protected]':
Traceback (most recent call last):
File "/Users/tylere/miniconda3/envs/test-release-3/bin/nbdev_release_gh", line 33, in <module>
sys.exit(load_entry_point('nbdev', 'console_scripts', 'nbdev_release_gh')())
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/script.py", line 119, in _f
return tfunc(**merge(args, args_from_prog(func, xtra)))
File "/Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py", line 132, in release_gh
ver = Release(token=token).release()
File "/Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py", line 89, in release
self.gh.create_release(ver, branch=self.cfg.branch, body=notes)
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 180, in create_release
rel = self.repos.create_release(tag_name, target_commitish=branch, name=name, body=body,
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 61, in __call__
return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 120, in __call__
res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=debug, return_headers=True,
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/net.py", line 218, in urlsend
return urlread(req, return_json=return_json, return_headers=return_headers)
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/net.py", line 119, in urlread
if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp, msg=e.msg) from None
fastcore.net.HTTP422UnprocessableEntityError: HTTP Error 422: Unprocessable Entity
====Error Body====
{
"message": "Validation Failed",
"errors": [
{
"resource": "Release",
"code": "custom",
"field": "tag_name",
"message": "tag_name is not a valid tag"
},
{
"resource": "Release",
"code": "custom",
"message": "Published releases must have a valid tag"
},
{
"resource": "Release",
"code": "invalid",
"field": "target_commitish"
}
],
"documentation_url": "https://docs.github.com/rest/reference/repos#create-a-release"
}
Hmm OK... Maybe add a breakpoint here?:
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 61, in __call__
return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
Or add a line print(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)? See if it all looks OK? Feel free to paste it here (with any auth stuff removed) if you're not sure.
(Sorry it's a bit tricky for me to debug directly since I don't know how to repro the problem)
Looks like most of the variables are empty:
(test-release-3) tylere-macbookpro5:test-release-3 tylere$ nbdev_release_gh
> /Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py(62)__call__()
-> return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
(Pdb) w
/Users/tylere/miniconda3/envs/test-release-3/bin/nbdev_release_gh(33)<module>()
-> sys.exit(load_entry_point('nbdev', 'console_scripts', 'nbdev_release_gh')())
/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/script.py(119)_f()
-> return tfunc(**merge(args, args_from_prog(func, xtra)))
/Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py(127)release_gh()
-> Release().changelog()
/Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py(72)changelog()
-> try: self.commit_date = self.gh.repos.get_latest_release().published_at
> /Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py(62)__call__()
-> return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
(Pdb) p self.path
'/repos/tylere/test-release-3/releases/latest'
(Pdb) p self.verb
'get'
(Pdb) p headers
{}
(Pdb) p route_p
{}
(Pdb) p query_p
{}
(Pdb) p data_p
{}
Moving up the stack, it can't seem to find the latest release. (Which I suppose makes sense, because the GitHub website states that there are "No releases published".)
(Pdb) u
> /Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py(72)changelog()
-> try: self.commit_date = self.gh.repos.get_latest_release().published_at
(Pdb) p self.gh.repos.get_latest_release()
*** fastcore.net.HTTP404NotFoundError: HTTP Error 404: Not Found
====Error Body====
{
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest/reference/repos#get-the-latest-release"
}
(Sorry it's a bit tricky for me to debug directly since I don't know how to repro the problem)
No worries at all. I value learning debugging techniques more than having a specific problem solved. Seems more scaleable.
I see limited use of a GHAPI_DEBUG env var in the github.com/fastai/ghapi repo, but nothing on how it is intended to be used. Are there a set of debugging env vars that can be used for the fastai libraries? While debugging I have wished for a way to trigger a verbose debug mode for the nbdev commands, which could log debugging statements when the commands call other libraries (ghapi, juypter, quarto, etc). Something like:
nbdev_release_gh --debug
Whoops, I didn't realize the code was called repeatedly. Removing the breakpoint and adding the print statement yields:
(test-release-3) tylere-macbookpro5:test-release-3 tylere$ nbdev_release_gh
DEBUG /repos/tylere/test-release-3/releases/latest get {} {} {} {}
DEBUG /repos/tylere/test-release-3/issues get {} {} {'state': 'closed', 'labels': 'breaking', 'sort': 'created', 'since': '2000-01-01T00:00:004Z'} {}
DEBUG /repos/tylere/test-release-3/issues get {} {} {'state': 'closed', 'labels': 'enhancement', 'sort': 'created', 'since': '2000-01-01T00:00:004Z'} {}
DEBUG /repos/tylere/test-release-3/issues get {} {} {'state': 'closed', 'labels': 'bug', 'sort': 'created', 'since': '2000-01-01T00:00:004Z'} {}
which seems suspect, since there is a closed "enhancement" issue:

Yeah just doing something like GHAPI_DEBUG=1 nbdev_release_gh should print info on every API call. Sorry I forgot that existed!
In the above output, you don't seem to be showing the actual failing call. The last call is to issues get, but the call that failed was the one that creates a release.
(BTW in your pdb thing, you could have hit s to step into that function, then args to see all the args at once without having to print each separately.)
Here is the entire printout, using GHAPI_DEBUG=1
(test-release-3) tylere-macbookpro5:test-release-3 tylere$ GHAPI_DEBUG=1 nbdev_release_gh
{'data': None,
'full_url': 'https://api.github.com/repos/tylere/test-release-3/releases/latest',
'headers': {'Accept': 'application/vnd.github.v3+json'},
'method': 'GET'}
{'data': None,
'full_url': 'https://api.github.com/repos/tylere/test-release-3/issues?state=closed&labels=breaking&sort=created&since=2022-09-16T01%3A53%3A57Z',
'headers': {'Accept': 'application/vnd.github.v3+json'},
'method': 'GET'}
{'data': None,
'full_url': 'https://api.github.com/repos/tylere/test-release-3/issues?state=closed&labels=enhancement&sort=created&since=2022-09-16T01%3A53%3A57Z',
'headers': {'Accept': 'application/vnd.github.v3+json'},
'method': 'GET'}
{'data': None,
'full_url': 'https://api.github.com/repos/tylere/test-release-3/issues?state=closed&labels=bug&sort=created&since=2022-09-16T01%3A53%3A57Z',
'headers': {'Accept': 'application/vnd.github.v3+json'},
'method': 'GET'}
Make release now? (y/n) y
{'data': b'{"tag_name": "0.0.1", "target_commitish": "master", "name": "v0.0.1"'
b', "body": "### New Features\\n\\n- Test issue ([#1](https://github'
b'.com/tylere/test-release-3/issues/1))\\n - Just a test issue, la'
b'beled as an enhancement.", "draft": false, "prerelease": false}',
'full_url': 'https://api.github.com/repos/tylere/test-release-3/releases',
'headers': {'Accept': 'application/vnd.github.v3+json'},
'method': 'POST'}
Traceback (most recent call last):
File "/Users/tylere/miniconda3/envs/test-release-3/bin/nbdev_release_gh", line 33, in <module>
sys.exit(load_entry_point('nbdev', 'console_scripts', 'nbdev_release_gh')())
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/script.py", line 119, in _f
return tfunc(**merge(args, args_from_prog(func, xtra)))
File "/Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py", line 132, in release_gh
ver = Release(token=token).release()
File "/Users/tylere/Documents/GitHub/fastai/nbdev/nbdev/release.py", line 89, in release
self.gh.create_release(ver, branch=self.cfg.branch, body=notes)
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 182, in create_release
rel = self.repos.create_release(tag_name, target_commitish=branch, name=name, body=body,
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 63, in __call__
return self.client(self.path, self.verb, headers=headers, route=route_p, query=query_p, data=data_p)
File "/Users/tylere/Documents/GitHub/fastai/ghapi/ghapi/core.py", line 122, in __call__
res,self.recv_hdrs = urlsend(path, verb, headers=headers or None, debug=debug, return_headers=True,
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/net.py", line 218, in urlsend
return urlread(req, return_json=return_json, return_headers=return_headers)
File "/Users/tylere/Documents/GitHub/fastai/fastcore/fastcore/net.py", line 119, in urlread
if 400 <= e.code < 500: raise ExceptionsHTTP[e.code](e.url, e.hdrs, e.fp, msg=e.msg) from None
fastcore.net.HTTP422UnprocessableEntityError: HTTP Error 422: Unprocessable Entity
====Error Body====
{
"message": "Validation Failed",
"errors": [
{
"resource": "Release",
"code": "custom",
"field": "tag_name",
"message": "tag_name is not a valid tag"
},
{
"resource": "Release",
"code": "custom",
"message": "Published releases must have a valid tag"
},
{
"resource": "Release",
"code": "invalid",
"field": "target_commitish"
}
],
"documentation_url": "https://docs.github.com/rest/reference/repos#create-a-release"
}
I think I have uncovered the root of the problem. I created the repository with the GitHub website, and GitHub now uses "main" as the default branch name, while nbdev_new creates a settings.ini file with branch = master. This causes the target_commitish parameter to be invalid.
Updating settings.ini to use branch = main allows nbdev_release_gh to succeed. I filed #1080 so that users don't have to do this.