atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.29k stars 642 forks source link

JIRA: Missing error msg #1363

Closed itsidorkin closed 1 month ago

itsidorkin commented 2 months ago

Related: #919 #1154

Starting from version 3.32.2, the cause of the error disappeared.

For example:

from atlassian import Jira

jira = Jira(
    url="https://mysite.com",
    username="username",
    password="password"
)

fields = {
    "summary": "this summary"
}

jira.issue_create(fields)

In version 3.32.1 the error text looked like this:

Traceback (most recent call last):
  File "...\mwv.py", line 14, in <module>
    jira.issue_create(fields)
  File "...\.venv\Lib\site-packages\atlassian\jira.py", line 1250, in issue_create
    return self.post(url, data={"fields": fields})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\atlassian\rest_client.py", line 310, in post
    response = self.request(
               ^^^^^^^^^^^^^
  File "...\.venv\Lib\site-packages\atlassian\rest_client.py", line 243, in request
    self.raise_for_status(response)
  File "...\.venv\Lib\site-packages\atlassian\rest_client.py", line 405, in raise_for_status
    raise HTTPError(error_msg, response=response)
requests.exceptions.HTTPError: project: project is required

In versions after 3.32.1 (and in the current version 3.41.11 too), the error text looks like this:

Traceback (most recent call last):
  File "...\mwv.py", line 14, in <module>
    jira.issue_create(fields)
  File "...\.venv2\Lib\site-packages\atlassian\jira.py", line 1537, in issue_create
    return self.post(url, data={"fields": fields})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...\.venv2\Lib\site-packages\atlassian\rest_client.py", line 388, in post
    response = self.request(
               ^^^^^^^^^^^^^
  File "...\.venv2\Lib\site-packages\atlassian\rest_client.py", line 312, in request
    self.raise_for_status(response)
  File "...\.venv2\Lib\site-packages\atlassian\rest_client.py", line 549, in raise_for_status
    raise HTTPError(error_msg, response=response)
requests.exceptions.HTTPError

project: project is required is not printed.

def raise_for_status in the rest_client.py file of the current version (3.41.11)

Open the file at line 539. If we runprint(errors) we get: {'project': 'project is required'}. Note that the key is a field that is necessary to create a ticket and which is not in the fields variable. However, on line 541 we do errors.get("message", ""). Of course, inside errors there is no message key, so the error text errors does not end up in error_msg