Skip to content

Attempting to delete a comment without permission to do so gets stuck in a loop #1249

Open
@pradcliffe-ns

Description

@pradcliffe-ns

Bug summary

I'm seeing a problem in debug logging when attempting to delete a comment that the user does not seem to have permission to delete. What I would expect is a JIRAerror exception with details, what is happening is the DELETE returns 400, urllib3 resets the dropped connection and then retries the delete forever.

I've worked around this by checking the comment.author.emailAddress matches the user making the attempt but if the delete fails for another reason this will still get stuck in a loop.

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

No response

jira-python version

3.1.1

Python Interpreter version

3.9.1

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

#!/usr/bin/env python3

import logging
from jira import JIRA, JIRAError

jirauser='user@example.com'
apikey='xxxxxx'
jiraurl='https://example.atlassian.net/'
ticket='EXA-1951'

logformat='%(asctime)s: %(pathname)s: %(message)s'
logging.basicConfig(level=loglevel, format=logformat)

jira=JIRA(basic_auth=(jirauser, apikey),
                server=args.jiraurl,
                options={
                  "headers": {
                    "User-Agent": user_agent("testing.py", "0.0.1")
                  }
                })

issue=jira.issue(ticket, fields='comments')
comments=jira.comments(issue)

for comment in comments:
  print('Deleting comment %s' % comment)
  try:
    comment.delete()
  except JIRAError as e:
    if "You do not have permission to delete comment" in e.text:
      print('No permission to delete comment %s, skipping' % comment)
      continue


### Stack trace

```python
Debug logs

2021-12-01 12:27:58,001: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: Starting new HTTPS connection (1): example.atlassian.net:443
2021-12-01 12:27:58,232: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "GET /rest/api/2/serverInfo HTTP/1.1" 200 None
2021-12-01 12:27:58,647: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "GET /rest/api/2/field HTTP/1.1" 200 None
2021-12-01 12:27:59,217: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "GET /rest/api/2/issue/MON-1951?fields=comments HTTP/1.1" 200 None
2021-12-01 12:28:16,592: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "GET /rest/api/2/issue/MON-1951/comment HTTP/1.1" 200 None
Deleting comment 1120692
2021-12-01 12:28:22,674: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "DELETE /rest/api/2/issue/350976/comment/1120692 HTTP/1.1" 400 None
2021-12-01 12:28:22,677: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: Resetting dropped connection: example.atlassian.net
2021-12-01 12:28:22,958: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "DELETE /rest/api/2/issue/350976/comment/1120692 HTTP/1.1" 400 None
2021-12-01 12:28:22,962: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: Resetting dropped connection: example.atlassian.net
2021-12-01 12:28:23,251: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "DELETE /rest/api/2/issue/350976/comment/1120692 HTTP/1.1" 400 None
2021-12-01 12:28:23,255: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: Resetting dropped connection: example.atlassian.net
2021-12-01 12:28:23,580: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "DELETE /rest/api/2/issue/350976/comment/1120692 HTTP/1.1" 400 None
2021-12-01 12:28:23,585: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: Resetting dropped connection: example.atlassian.net
2021-12-01 12:28:23,907: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "DELETE /rest/api/2/issue/350976/comment/1120692 HTTP/1.1" 400 None
2021-12-01 12:28:23,912: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: Resetting dropped connection: example.atlassian.net
2021-12-01 12:28:24,401: /usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py: https://example.atlassian.net:443 "DELETE /rest/api/2/issue/350976/comment/1120692 HTTP/1.1" 400 None
[goes on forever]


### Expected behaviour

Raise a JIRAError and skip.

### Additional Context

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions