jira
jira copied to clipboard
log detail miss between jira-3.2.0 and jira-3.4.1
Bug summary
Hi! This week I update jira lib from 3.2.0 to 3.4.1, after this update, when create issue failed, there is no enough log detail
in 3.2.0
2023-02-06 14:22:40,311 - DEBUG - 4410643968 - https://xxxx.atlassian.net:443 "GET /rest/api/2/project/xxx HTTP/1.1" 200 None
2023-02-06 14:22:40,839 - DEBUG - 4410643968 - https://xxx.atlassian.net:443 "POST /rest/api/2/issue HTTP/1.1" 400 None
The issue type selected is invalid.
in 3.4.1
2023-02-06 14:08:30,833 - DEBUG - 4556871168 - https://xxx.atlassian.net:443 "GET /rest/api/2/project/xxx HTTP/1.1" 200 None
2023-02-06 14:08:31,259 - DEBUG - 4556871168 - https://xxx.atlassian.net:443 "POST /rest/api/2/issue HTTP/1.1" 400 None
Is there an existing issue for this?
- [X] I have searched the existing issues
Jira Instance type
Jira Cloud (Hosted by Atlassian)
Jira instance version
NONE
jira-python version
3.4.1
Python Interpreter version
3.10.5
Which operating systems have you used?
- [ ] Linux
- [X] macOS
- [ ] Windows
Reproduction steps
# 1. Given a Jira client instance
jira: JIRA
# 2. When I call the function with argument required field missing
jira.create_issue(x)
# 3. 400 but no log detail
Stack trace
2023-02-06 14:08:30,833 - DEBUG - 4556871168 - https://xxx.atlassian.net:443 "GET /rest/api/2/project/xxx HTTP/1.1" 200 None
2023-02-06 14:08:31,259 - DEBUG - 4556871168 - https://xxx.atlassian.net:443 "POST /rest/api/2/issue HTTP/1.1" 400 None
Expected behaviour
print the error detail
Additional Context
No response
I was somewhat able to reproduce this error
I used the following:
jira: JIRA
try:
issue = jira.create_issue(
summary="Test issue created",
project=jira.projects()[0].key,
issuetype={"name": "BadIssueType"},
description="foo description",
)
except Exception as e:
print("String print:" + str(e)) # empty
print(e.text) # '{"errorMessages":[],"errors":{"issuetype":"Specify an issue type"}}'
# raise e # Raises traceback as expected
This is the exception raised:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\adeha\Documents\GitHub\jira\jira\client.py", line 1521, in create_issue
r = self._session.post(url, data=json.dumps(data))
File "C:\Users\adeha\Documents\GitHub\jira\.tox\py310\lib\site-packages\requests\sessions.py", line 635, in post
return self.request("POST", url, data=data, json=json, **kwargs)
File "C:\Users\adeha\Documents\GitHub\jira\jira\resilientsession.py", line 241, in request
elif raise_on_error(response, **processed_kwargs):
File "C:\Users\adeha\Documents\GitHub\jira\jira\resilientsession.py", line 69, in raise_on_error
raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 400 url: https://pycontribs.atlassian.net/rest/api/2/issue
response headers = { ... }
response text = {"errorMessages":[],"errors":{"issuetype":"Specify an issue type"}}
Therefore the issue lies in in the parser for error messages, where we are using an elseif
condition and therefore missing the errors
key after parsing the first empty list in errorMessages
.
I think the best option is to not use an else if condition and instead keep appending error messages as we go through the returned dictionary. Although perhaps we don't need to try anything fancy and simply return the response as it is, perhaps a simple json.dumps(e.text, indent=4)
or equivalent may suffice to make it readable.
@studioj any thoughts?
We had the same issue here at my company trying out the new version. I agree that removing the else
will resolve this.
Complementary to this change, I'd suggest combining the conditions with a value check on the repository, to also use python truthiness check and validate that even if the key exist, it should have an actual value (sorry, I couldn't resist adding some walrus operators to make things more pythonic :sweat_smile: )
if "message" in resp_data:
# ...
elif resp_errors := resp_data.get("errorMessage", [])
# ...
elif resp_errors := resp_data.get("errorMessages", []):
# ...
elif resp_errors := resp_data.get("errors", []):
# ...
return parsed_errors