pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.92k stars 857 forks source link

Calling add_user() on Jira Cloud instances fails with: You must specify the products that user can access. #1869

Open kot0dama opened 2 weeks ago

kot0dama commented 2 weeks ago

Bug summary

Calling add_user() on Jira Cloud instances fails with this error: You must specify the products that user can access.

This seems to be a new requirement on Jira Cloud instances from about 2 weeks ago.

Is there an existing issue for this?

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

No response

jira-python version

3.5.2-1

Python Interpreter version

3.12.3

Which operating systems have you used?

Reproduction steps

# 1. Given a Jira client instance
jira: JIRA
# 2. When I call the add_user with either of these arguments
jira.add_user(username="REDACTED", email="REDACTED", fullname="REDACTED", notify=True, application_keys=["jira-software"])
jira.add_user(username="REDACTED", email="REDACTED", fullname="REDACTED", notify=True)

Stack trace

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/jira/client.py", line 4630, in add_user
    raise e
  File "/usr/lib/python3/dist-packages/jira/client.py", line 4620, in add_user
    self._session.post(url, data=payload)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/jira/resilientsession.py", line 246, in request
    elif raise_on_error(response, **processed_kwargs):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/jira/resilientsession.py", line 71, in raise_on_error
    raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 400 url: https://REDACTED/rest/api/latest/user
        text: You must specify the products that user can access.

        response headers = REDACTED
        response text = {"errorMessages":["You must specify the products that user can access."],"errors":{}}

Expected behaviour

add_user() method shall comply with Jira Cloud requirements, and send a product list.

Calling a modified add_user() method, adding products like this fixes it: https://github.com/pycontribs/jira/blob/main/jira/client.py#L5126

         if notify:
             x["notification"] = "True"
+       if products is not None:
+           x["products"] = products
         if application_keys is not None:
             x["applicationKeys"] = application_keys

Tested and confirmed working with products = ["jira-software"]

Thank you, Loïc

Additional Context

No response