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

Adding a formatted comment isn't working with v3 API #1556

Open
2 of 4 tasks
armaandhull opened this issue Nov 23, 2022 · 1 comment
Open
2 of 4 tasks

Adding a formatted comment isn't working with v3 API #1556

armaandhull opened this issue Nov 23, 2022 · 1 comment

Comments

@armaandhull
Copy link

armaandhull commented Nov 23, 2022

Bug summary

Adding a formatted comment isn't working using this package. When the same POST request is made using the requests library directly, the functionality works as expected.

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", "3.4.1"

Python Interpreter version

3.9

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

# 1. Given a Jira client instance
jira = JIRA(basic_auth=('email', 'API token'))
comment = json.dumps( {
  "body": {
    "type": "doc",
    "version": 1,
    "content": [
      {
        "type": "codeBlock",
        "content": [
          {
            "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
            "type": "text"
          }
        ]
      }
    ]
  }
} )
# 2. When I call the function with argument x
jira.add_comment("AB-123", comment)

Stack trace

File "/home/devuser/.local/lib/python3.9/site-packages/jira/client.py", line 119, in wrapper
    result = func(*arg_list, **kwargs)
  File "/home/devuser/.local/lib/python3.9/site-packages/jira/client.py", line 1913, in add_comment
    r = self._session.post(url, data=json.dumps(data))
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 577, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/devuser/.local/lib/python3.9/site-packages/jira/resilientsession.py", line 223, in request
    elif raise_on_error(response, **processed_kwargs):
  File "/home/devuser/.local/lib/python3.9/site-packages/jira/resilientsession.py", line 69, in raise_on_error
    raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 400 url: https://<domain>.atlassian.net/rest/api/3/issue/AB-123/comment
	
	response headers = {'Date': 'Wed, 23 Nov 2022 15:57:05 GMT', 'Content-Type': 'application/json;charset=UTF-8', 'Server': 'AtlassianEdge', 'Timing-Allow-Origin': '*', 'X-Arequestid': '70a7fee061f08aa96a25a10cc4d9aaba', 'X-Aaccountid': '5bcf8382359ddf204e8c5925', 'Cache-Control': 'no-cache, no-store, no-transform', 'Expect-Ct': 'report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/atlassian-proxy", max-age=86400', 'Strict-Transport-Security': 'max-age=63072000; preload', 'X-Content-Type-Options': 'nosniff', 'X-Xss-Protection': '1; mode=block', 'Atl-Traceid': 'ab62d530d115d376', 'Report-To': '{"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}', 'Nel': '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}', 'Transfer-Encoding': 'chunked'}
	response text = {"errorMessages":[],"errors":{"comment":"Comment body is not valid!"}}

Expected behaviour

Formatted comment is added to the JIRA issue

image

Additional Context

No response

@princenyeche
Copy link

princenyeche commented Nov 30, 2022

Hey @armaandhull
This is not a bug, you're sending the wrong body content hence the 400 error. That's why the error mentions that the comment body isn't valid.
Regarding the 400 error, the class for Comment already sends the "body" key in the payload as it's constructed for it, so there's no need to add it again.

What you need to do is

# 1. Given a Jira client instance
jira = JIRA(basic_auth=('email', 'API token'))
# remove the body key as call the value
comment = {
    "type": "doc",
    "version": 1,
    "content": [
      {
        "type": "codeBlock",
        "content": [
          {
            "text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
            "type": "text"
          }
        ]
      }
    ]
  }

jira.add_comment("AB-123", comment)

Edited: I looked at the error again and noticed you're already on v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants