jira icon indicating copy to clipboard operation
jira copied to clipboard

Erroneous Warnings When Creating Issue Links

Open ssamsel-rtx opened this issue 1 year ago • 7 comments

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?

  • [X] 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?

  • [X] 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 avatar Jul 16 '24 14:07 ssamsel-rtx

I have the same issue.

Lenormju avatar Oct 10 '24 07:10 Lenormju

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

Ket3r avatar Oct 25 '24 12:10 Ket3r

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.

matthiasxv250 avatar Oct 30 '24 09:10 matthiasxv250

the only change needed is : instead of => issue_link_types = self.issue_link_types() change to => issue_link_types = [ilt.name for ilt in self.issue_link_types()]

tested and working

adoniadi-stm avatar Feb 12 '25 12:02 adoniadi-stm

I confirm the solution of @adoniadi-stm. Environment: Jira Service Management (Cloud).

michaelpoersch avatar Feb 20 '25 07:02 michaelpoersch

Yeah, problem there is a bit larger as giving IssueLinkType type fails completely because it's given to data dict and isn't serializable. Had to fix this in calling code so I can use link types. Would have to invest some time to create a PR to fix this.

as background: Blocks linktypes name is Blocks, but this code only accepts blocks because it's inward issue type that is checked in that backup "smart" loop. :)

PolarFox avatar Feb 24 '25 06:02 PolarFox

always open for a fix @PolarFox although our release pipeline is a bit broken

studioj avatar Apr 01 '25 21:04 studioj

I have this fix:

diff --git a/jira/client.py b/jira/client.py
index 217d46e..4f9f7f6 100644
--- a/jira/client.py
+++ b/jira/client.py
@@ -2961,7 +2961,7 @@ class JIRA:
                     break
 
         data = {
-            "type": {"name": type},
+            "type": {"name": str(type)},
             "inwardIssue": {"key": inwardIssue},
             "outwardIssue": {"key": outwardIssue},
             "comment": comment,

MarkusPietrek avatar Jun 25 '25 06:06 MarkusPietrek

To work around this without patching the jira code you can also do something like this:

class SkipJiraFP(logging.Filter):
    def filter(self, record):
        # Avoid a false positive warning from the jira library https://github.com/pycontribs/jira/issues/1875
        return record.getMessage() != "Warning: Specified issue link type is not present in the list of link types"

logging.getLogger("jira").addFilter(SkipJiraFP())

though of course this will also suppress legitimate warnings so is not ideal

sparrowt avatar Nov 13 '25 13:11 sparrowt