Skip to content

Commit bdeaf3d

Browse files
authored
[bug][jira] jira get_issue_tree_recursive method overwrites default params values from previous executions (#1461)
* added two new methods: download_attachments.from_issue and get_attachments_ids_from_issue --------- Co-authored-by: gkowalc <> Co-authored-by: Greg <gkowalc>
1 parent 9b40bb1 commit bdeaf3d

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

atlassian/jira.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,20 +1730,21 @@ def get_issue_remote_links(self, issue_key, global_id=None, internal_id=None):
17301730
url += "/" + internal_id
17311731
return self.get(url, params=params)
17321732

1733-
def get_issue_tree_recursive(self, issue_key, tree=[], depth=0):
1734-
"""
1735-
Returns list that contains the tree structure of the root issue, with all subtasks and inward linked issues.
1736-
(!) Function only returns child issues from the same jira instance or from instance to which api key has access to.
1737-
(!) User asssociated with API key must have access to the all child issues in order to get them.
1738-
:param jira issue_key:
1739-
:param tree: blank parameter used for recursion. Don't change it.
1740-
:param depth: blank parameter used for recursion. Don't change it.
1741-
:return: list of dictioanries, key is the parent issue key, value is the child/linked issue key
1742-
1743-
"""
1744-
1733+
def get_issue_tree_recursive(self, issue_key, tree=None, depth=None):
1734+
"""
1735+
Returns a list that contains the tree structure of the root issue, with all subtasks and inward linked issues.
1736+
(!) Function only returns child issues from the same Jira instance or from an instance to which the API key has access.
1737+
:param issue_key: Jira issue key
1738+
:param tree: list to store the tree structure for recursion. Do not change it.
1739+
:param depth: current depth of the tree for recursion. Do not change it.
1740+
:return: list of dictionaries containing the tree structure. Dictionary element contains a key (parent issue) and value (child issue).
1741+
"""
1742+
if tree is None:
1743+
tree = []
1744+
if depth is None:
1745+
depth = 0
17451746
# Check the recursion depth. In case of any bugs that would result in infinite recursion, this will prevent the function from crashing your app. Python default for REcursionError is 1000
1746-
if depth > 50:
1747+
if depth > 150:
17471748
raise Exception("Recursion depth exceeded")
17481749
issue = self.get_issue(issue_key)
17491750
issue_links = issue["fields"]["issuelinks"]
@@ -1761,9 +1762,9 @@ def get_issue_tree_recursive(self, issue_key, tree=[], depth=0):
17611762
for subtask in subtasks:
17621763
if subtask.get("key") is not None:
17631764
parent_issue_key = issue["key"]
1764-
if not [x for x in tree if subtask["key"] in x.keys()]: # condition to avoid infinite recursion
1765+
if not [x for x in tree if subtask["key"] in x.keys()]:
17651766
tree.append({parent_issue_key: subtask["key"]})
1766-
self.get_issue_tree_recursive(subtask["key"], tree, depth + 1) # recursive call of the function
1767+
self.get_issue_tree_recursive(subtask["key"], tree, depth + 1)
17671768
return tree
17681769

17691770
def create_or_update_issue_remote_links(

0 commit comments

Comments
 (0)