Skip to content

Commit e15349c

Browse files
nejchJohnVillalovos
authored andcommitted
fix(client): support empty 204 responses in http_patch
1 parent ff45124 commit e15349c

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

gitlab/client.py

+2
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,8 @@ def http_patch(
10831083
raw=raw,
10841084
**kwargs,
10851085
)
1086+
if result.status_code in gitlab.const.NO_JSON_RESPONSE_CODES:
1087+
return result
10861088
try:
10871089
json_result = result.json()
10881090
if TYPE_CHECKING:

gitlab/const.py

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class SearchScope(GitlabEnum):
9595

9696
USER_AGENT: str = f"{__title__}/{__version__}"
9797

98+
NO_JSON_RESPONSE_CODES = [204]
9899
RETRYABLE_TRANSIENT_ERROR_CODES = [500, 502, 503, 504] + list(range(520, 531))
99100

100101
__all__ = [

tests/unit/test_gitlab_http_methods.py

+15
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,21 @@ def test_patch_request(gl):
800800
assert responses.assert_call_count(url, 1) is True
801801

802802

803+
@responses.activate
804+
def test_patch_request_204(gl):
805+
url = "http://localhost/api/v4/projects"
806+
responses.add(
807+
method=responses.PATCH,
808+
url=url,
809+
status=204,
810+
match=helpers.MATCH_EMPTY_QUERY_PARAMS,
811+
)
812+
813+
result = gl.http_patch("/projects")
814+
assert isinstance(result, requests.Response)
815+
assert responses.assert_call_count(url, 1) is True
816+
817+
803818
@responses.activate
804819
def test_patch_request_404(gl):
805820
url = "http://localhost/api/v4/not_there"

0 commit comments

Comments
 (0)