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

PSQLException and timeouts on removing projects #1428

Closed thesefer closed 22 hours ago

thesefer commented 3 days ago

hi there

I have a rather simple function to delete projects with which I want to clean up a jira test instance. Unfortunately I still run into timeouts or other exceptions. What can I do to improve the situation?

def delete_projects(user,password):
    jira = Jira(
        url='',
        username=user,
        password=password,
        timeout=9999)

    projectlist = jira.projects(included_archived=True, expand=None)
    project_keys = []
    for project in projectlist:
        project_keys.append(project['key'])

    for key in project_keys:
        if key.lower() != 'PROJKEY':
            print("\nRemoving project: ", key)
            jira.delete_project(key)
            print("Project deleted")
    return

Despite setting a high timeout, I still run into timeouts:

Removing project:  PROJECT
Traceback (most recent call last):
  File "/jira/env/lib/python3.8/site-packages/requests/models.py", line 974, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/jira/env/lib/python3.8/site-packages/atlassian/rest_client.py", line 535, in raise_for_status
    j = response.json()
  File "/jira/env/lib/python3.8/site-packages/requests/models.py", line 978, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "delete_projects.py", line 41, in <module>
    main()
  File "delete_projects.py", line 36, in main
    delete_projects(user,password)
  File "delete_projects.py", line 20, in delete_projects
    jira.delete_project(key)
  File "/jira/env/lib/python3.8/site-packages/atlassian/jira.py", line 2495, in delete_project
    return self.delete(url)
  File "/jira/env/lib/python3.8/site-packages/atlassian/rest_client.py", line 508, in delete
    response = self.request(
  File "/jira/env/lib/python3.8/site-packages/atlassian/rest_client.py", line 313, in request
    self.raise_for_status(response)
  File "/jira/env/lib/python3.8/site-packages/atlassian/rest_client.py", line 550, in raise_for_status
    response.raise_for_status()
  File "/jira/env/lib/python3.8/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 504 Server Error: Gateway Time-out for url: https://url/rest/api/2/project/PROJECT

And sometimes after this I get a PSQLException-Error

Removing project:  PROJECT
Traceback (most recent call last):
  File "delete_projects.py", line 41, in <module>
    main()
  File "delete_projects.py", line 36, in main
    delete_projects(user,password)
  File "delete_projects.py", line 20, in delete_projects
    jira.delete_project(key)
  File "/jira/env/lib/python3.8/site-packages/atlassian/jira.py", line 2495, in delete_project
    return self.delete(url)
  File "/jira/env/lib/python3.8/site-packages/atlassian/rest_client.py", line 508, in delete
    response = self.request(
  File "/jira/env/lib/python3.8/site-packages/atlassian/rest_client.py", line 313, in request
    self.raise_for_status(response)
  File "/jira/env/lib/python3.8/site-packages/atlassian/rest_client.py", line 552, in raise_for_status
    raise HTTPError(error_msg, response=response)
requests.exceptions.HTTPError: Exception removing project: Error removing issues: com.querydsl.core.QueryException: Caught PSQLException for update public.issuelink
set sequence = ?
where issuelink.id = ?