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

create_issue_link crashes when passing named argument type as IssueLinkType #1835

Open
2 of 4 tasks
jojochims opened this issue Mar 6, 2024 · 0 comments
Open
2 of 4 tasks

Comments

@jojochims
Copy link

jojochims commented Mar 6, 2024

Bug summary

The create_issue_link function crashes when an IssueLinkType object is passed to the function as the link type.

There has been a similar previous issue #1604 which was fixed by converting the IssueLinkType to a string when calling the create_issue_link function using positional arguments. In this case, the create_issue_link function displays a warning and figures out the correct IssueLinkType on its own.

If an IssueLinkType is handed to create_issue_link using named arguments, the automatic conversion of the arguments is skipped (as it was added in #1604). The warning in create_issue_link is not displayed as the provided link type is found in the list of valid link types. In the next step, the IssueLinkType is however passed directly to the post function and thus creates a TypeError: Object of type IssueLinkType is not JSON serializable

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Server or Data Center (Self-hosted)

Jira instance version

9.4.15

jira-python version

3.6.0

Python Interpreter version

3.11

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

jira: JIRA

jira_link_type = jira.issue_link_types()
# take any valid link type
link_type = link_types[0]

issue1 = "key1"
issue2 = "key2"

# link the issues
jira.create_issue_link(
     type=link_type, 
     inwardIssue = issue1,
     outwardIssue = issue2 
)

Stack trace

(...)
    (...)jira.create_issue_link(
  File "(...)\client.py", line 124, in wrapper
    result = func(*arg_list, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "(...)\client.py", line 2548, in create_issue_link
    return self._session.post(url, data=json.dumps(data))
                                        ^^^^^^^^^^^^^^^^
  File "(...)\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "(...)\json\encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "(...)\json\encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "(...)\json\encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type IssueLinkType is not JSON serializable

Expected behaviour

In the create_issue_link function the type of the variable "type" needs to be checked before creating the data Dictionary. If it is of type IssueLinkType, the data Dictionary needs to be handed the name of the link type instead of the IssueLinkType object, e.g.:

data = {
    "type": {"name": type.name},
    "inwardIssue": {"key": inwardIssue},
    "outwardIssue": {"key": outwardIssue},
    "comment": comment,
}

Additional Context

No response

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

1 participant