Repository navigation
Conversation
Failed HEAD responses normally have no body, so Gitlab.http_request() left error_message empty and raised errors rendered as "404: ". Fall back to the response reason phrase, or the standard HTTPStatus phrase when the server did not provide one, only when no message could be parsed from the response. JSON response messages still take precedence, and response_body remains unchanged. Add regression coverage for the low-level HEAD path, ProjectFileManager.head(), and JSON message precedence. Fixes python-gitlab#3461
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3467 +/- ##
=======================================
Coverage 95.78% 95.79%
=======================================
Files 100 100
Lines 6172 6179 +7
=======================================
+ Hits 5912 5919 +7
Misses 260 260
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Exercise the defensive ValueError path used when the server returns a status code that is not part of http.HTTPStatus, so the fallback does not mask the original GitlabHttpError.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Fixes #3461
Problem
A failed HEAD request has no response body by HTTP semantics. For example:
This makes logs and CLI output show an empty error message even though the HTTP status has a standard reason phrase.
Root cause
Gitlab.http_request()initializeserror_messagefromresult.contentand then tries to replace it with the JSONmessage/errorfield. For a bodyless HEAD error,result.contentisb""andresult.json()raisesValueError, so both attempts leave the message empty.GitlabErrorthen decodes that empty value andGitlabError.__str__()renders"<status>: ".The specialized
GitlabHeadErrorraised byProjectFileManager.head()receives the same empty message throughon_http_error.Solution
When no error message was parsed from the response, fall back to:
http.HTTPStatus.The change is limited to error-message construction:
response_codeis unchanged;response_bodyremains exactly what the server returned (includingb""for HEAD);message/errorvalues still take precedence;Validation
Added regression coverage for:
Gitlab.http_request()/http_head()level;project.files.head()path, includingGitlabHeadErrorandstr(exc);GitlabHttpErrorinstead of a fallback lookup error.Local verification on Python 3.13:
pytest -q tests/unit/test_gitlab_http_methods.py tests/unit/objects/test_repositories.py— 65 passedpytest -q tests/unit— 726 passed, 3 skippedtox -e black -- --check— passedtox -e isort -- --check-only --diff— passedtox -e flake8— passedtox -e mypy— passedtox -e pylint— passed (10.00/10)cz check --rev-range HEAD~1..HEAD— passedA standalone reproduction of the issue now reports
error_message='Not Found'andstr(exc)='404: Not Found', withresponse_body=b''.Functional tests were not run because they require a Dockerized GitLab instance; the regression is covered by mocked HTTP unit tests matching the issue's reproduction.
Impact
Small, backward-compatible error-reporting improvement. The only visible behavior change is that empty error messages for bodyless failed responses now include an HTTP reason phrase instead of trailing whitespace.
Documentation and testing
project.files.head()path, and JSON-message precedence