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

Erroneous Warnings When Creating Issue Links #1875

Open
2 of 4 tasks
ssamsel-rtx opened this issue Jul 16, 2024 · 3 comments · May be fixed by #1876
Open
2 of 4 tasks

Erroneous Warnings When Creating Issue Links #1875

ssamsel-rtx opened this issue Jul 16, 2024 · 3 comments · May be fixed by #1876

Comments

@ssamsel-rtx
Copy link

Bug summary

When creating issue links, I get a warning log informing me that the issue link type I specify is not present in the list of link types, even if it is in fact present. This is due to the equality of the IssueLinkType class and strings not working. Even when passing in the type argument as the appropriate IssueLinkType, this warning still occurs as the translate_resource_args decorator converts it to a string. This can be fixed by changing the line issue_link_types = self.issue_link_types() to issue_link_types = list(map(lambda x: x.name, self.issue_link_types())) in the JIRA.create_issue_link method in client.py

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

No response

jira-python version

main

Python Interpreter version

3.10.12

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

# 1. Given a Jira client instance
jira: JIRA
# 2. When I create an "is closely related to" issue link:
jira.create_issue_link("Closely Related To", "KEY-1", "KEY-2")
# 3. I get the erroneous warning
Warning: Specified issue link type is not present in the list of link types

Stack trace

n/a

Expected behaviour

I expect no warning, as the issue link is created correctly, and is in fact in the set of issue links returned by jira.issue_link_types()

Additional Context

No response

ssamsel-rtx pushed a commit to ssamsel-rtx/jira that referenced this issue Jul 17, 2024
Equality check between IssueLinkType and string always returns false.
Function decorator casts IssueLinkType parameters to string, so a
warning is always logged. This fixes that issue.

Closes: pycontribs#1875
Signed-off-by: Shymon Samsel <[email protected]>
@Lenormju
Copy link

I have the same issue.

@Ket3r
Copy link

Ket3r commented Oct 25, 2024

Same issue here. I even tried fetching the link types instead of using a string:

def _create_issue_links(issue_key, issue):
    created_issue = get_jira().issue(issue_key)
    # Get link types from jira
    link_types = get_jira().issue_link_types()
    verification_link_type = next(link for link in link_types if link.name == "Verification")

    for target in issue.link_verifies_keys:
        get_jira().create_issue_link(
            verification_link_type, inwardIssue=created_issue.key, outwardIssue=target
        )

But this still results in this warning log:

WARNING  jira:client.py:2935 Warning: Specified issue link type is not present in the list of link types

@matthiasxv250
Copy link

That's the code of the function create_issue_link:
# let's see if we have the right issue link 'type' and fix it if needed
issue_link_types = self.issue_link_types()

    if type not in issue_link_types:
        self.log.warning(
            "Warning: Specified issue link type is not present in the list of link types"
        )
        for lt in issue_link_types:
            if lt.outward == type:
                # we are smart to figure it out what he meant
                type = lt.name
                break
            elif lt.inward == type:
                # so that's the reverse, so we fix the request
                type = lt.name
                inwardIssue, outwardIssue = outwardIssue, inwardIssue
                break

    data = {
        "type": {"name": type},
        "inwardIssue": {"key": inwardIssue},
        "outwardIssue": {"key": outwardIssue},
        "comment": comment,
    }
    url = self._get_url("issueLink")
    return self._session.post(url, data=json.dumps(data))

Calling the function with a string as type we get the warning "Warning: Specified issue link type is not present in the list of link types"
Calling the function with a type which is an IssueLinkType object, we get the error TypeError: Object of type IssueLinkType is not JSON serializable which comes from the last line return self._session.post(url, data=json.dumps(data))
I think the class IssueLinkType needs to be adapted to support serializing.

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

Successfully merging a pull request may close this issue.

4 participants