Skip to content

Commit 7676b47

Browse files
Fix: Don't add empty json from default dictionary to GET payloads to avoid 403 from jira API. (#2322)
1 parent 8c1c339 commit 7676b47

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

jira/resilientsession.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _jira_prepare(self, **original_kwargs) -> dict:
180180
prepared_kwargs["headers"] = request_headers
181181

182182
data = original_kwargs.get("data", None)
183-
if isinstance(data, dict):
183+
if isinstance(data, dict) and data:
184184
# mypy ensures we don't do this,
185185
# but for people subclassing we should preserve old behaviour
186186
prepared_kwargs["data"] = json.dumps(data)

tests/test_resilientsession.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,13 @@ def test_verify_is_forwarded(mocked_request_method: Mock):
242242
session.get(url="mocked_url", data={"some": "fake-data"})
243243
kwargs = mocked_request_method.call_args.kwargs
244244
assert kwargs["verify"] == session.verify is False
245+
246+
247+
@patch("requests.Session.request")
248+
def test_empty_dict_body_not_forwarded(mocked_request_method: Mock):
249+
# Disable retries for this test.
250+
session = jira.resilientsession.ResilientSession(max_retries=0)
251+
# Empty dictionary should not be converted to JSON
252+
session.get(url="mocked_url", data={})
253+
kwargs = mocked_request_method.call_args.kwargs
254+
assert "data" not in kwargs

0 commit comments

Comments
 (0)