Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add empty json from default dictionary to GET payloads to avoid 403 from jira API. #2322

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jira/resilientsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _jira_prepare(self, **original_kwargs) -> dict:
prepared_kwargs["headers"] = request_headers

data = original_kwargs.get("data", None)
if isinstance(data, dict):
if isinstance(data, dict) and data:
# mypy ensures we don't do this,
# but for people subclassing we should preserve old behaviour
prepared_kwargs["data"] = json.dumps(data)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_resilientsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,13 @@ def test_verify_is_forwarded(mocked_request_method: Mock):
session.get(url="mocked_url", data={"some": "fake-data"})
kwargs = mocked_request_method.call_args.kwargs
assert kwargs["verify"] == session.verify is False


@patch("requests.Session.request")
def test_empty_dict_body_not_forwarded(mocked_request_method: Mock):
# Disable retries for this test.
session = jira.resilientsession.ResilientSession(max_retries=0)
# Empty dictionary should not be converted to JSON
session.get(url="mocked_url", data={})
kwargs = mocked_request_method.call_args.kwargs
assert "data" not in kwargs