python-coverage-comment-action
python-coverage-comment-action copied to clipboard
Diff fails when 300+ files have changed
My team has a large repo that's almost entirely code generated Python, and it's common for us to have very large PRs, as all the output is generated at once. We also generate unit tests for this code. Coverage hovers around 98%, and despite the huge amount of files/lines changed, the coverage metrics don't change much. It's useful to see the PR comment to catch cases where something changes unexpectedly.
python-coverage-comment-action failed on a recent PR, with the following stack trace. I haven't looked at the implementation, but the error message offers two alternative ways to generate the diff, and I thought I'd mention it. We've disabled the GitHub action for now, so this is not a critical issue.
Error: Critical error. This error possibly occurred because the permissions of the workflow are set incorrectly. You can see the correct setting of permissions here: https://github.com/py-cov-action/python-coverage-comment-action#basic-usage
Otherwise please look for open issues or open one in https://github.com/py-cov-action/python-coverage-comment-action/
Traceback (most recent call last):
File "/workdir/coverage_comment/github_client.py", line 89, in _http
response.raise_for_status()
File "/usr/local/lib/python3.12/site-packages/httpx/_models.py", line 829, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '406 Not Acceptable' for url 'https://api.github.com/repos/<redacted>/pulls/164'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/406
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/workdir/coverage_comment/main.py", line 46, in main
exit_code = action(
^^^^^^^
File "/workdir/coverage_comment/main.py", line 98, in action
return process_pr(
^^^^^^^^^^^
File "/workdir/coverage_comment/main.py", line 143, in process_pr
diff = github.get_pr_diff(
^^^^^^^^^^^^^^^^^^^
File "/workdir/coverage_comment/github.py", line 266, in get_pr_diff
.get(headers={"Accept": "application/vnd.github.v3.diff"})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workdir/coverage_comment/github_client.py", line 29, in __call__
return self._gh._http(self._method, self._path, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workdir/coverage_comment/github_client.py", line 96, in _http
raise cls(str(contents)) from exc
coverage_comment.github_client.ApiError: {'message': "Sorry, the diff exceeded the maximum number of files (300). Consider using 'List pull requests files' API or locally cloning the repository instead.", 'errors': [{'resource': 'PullRequest', 'field': 'diff', 'code': 'too_large'}], 'documentation_url': 'https://docs.github.com/rest/pulls/pulls#list-pull-requests-files', 'status': '406'}
before https://github.com/py-cov-action/python-coverage-comment-action/pull/573, we used to generate the diff locally. But then we changed that because it was much more complex and it's often not trivial to get an accurate diff given the PR might be outdated, and/or have merge commits etc, so we started using GitHub's diff as a way to get a diff everyone could agree on.
And now this :)
I think we should just detect 'code': 'too_large' and disable the diff.
Is it a contribution you'd be interested in doing ?
Haha, sorry to throw a wrench in your spokes! Yes I can take a look at contributing that. I'll look around the repo/project next week and get my bearings.
Just mentioning: in case someone else wants to tackle this, it's not reserved :)
Not sure if I should create another issue, but on the same train as that one:
the diff exceeded the maximum number of lines (20000)