@@ -109,6 +109,14 @@ def is_push_all_issues(instance):
109
109
return None
110
110
111
111
112
+ def _safely_get_finding_group_status (finding_group : Finding_Group ) -> str :
113
+ # Accommodating a strange behavior where a finding group sometimes prefers `obj.status` rather than `obj.status()`
114
+ try :
115
+ return finding_group .status ()
116
+ except TypeError : # TypeError: 'str' object is not callable
117
+ return finding_group .status
118
+
119
+
112
120
# checks if a finding can be pushed to JIRA
113
121
# optionally provides a form with the new data for the finding
114
122
# any finding that already has a JIRA issue can be pushed again to JIRA
@@ -161,13 +169,8 @@ def can_be_pushed_to_jira(obj, form=None):
161
169
elif isinstance (obj , Finding_Group ):
162
170
if not obj .findings .all ():
163
171
return False , f"{ to_str_typed (obj )} cannot be pushed to jira as it is empty." , "error_empty"
164
- # Accommodating a strange behavior where a finding group sometimes prefers `obj.status` rather than `obj.status()`
165
- try :
166
- not_active = "Active" not in obj .status ()
167
- except TypeError : # TypeError: 'str' object is not callable
168
- not_active = "Active" not in obj .status
169
172
# Determine if the finding group is not active
170
- if not_active :
173
+ if "Active" not in _safely_get_finding_group_status ( obj ) :
171
174
return False , f"{ to_str_typed (obj )} cannot be pushed to jira as it is not active." , "error_inactive"
172
175
173
176
else :
@@ -1101,7 +1104,7 @@ def issue_from_jira_is_active(issue_from_jira):
1101
1104
1102
1105
1103
1106
def push_status_to_jira (obj , jira_instance , jira , issue , * , save = False ):
1104
- status_list = obj . status ( )
1107
+ status_list = _safely_get_finding_group_status ( obj )
1105
1108
issue_closed = False
1106
1109
# check RESOLVED_STATUS first to avoid corner cases with findings that are Inactive, but verified
1107
1110
if any (item in status_list for item in RESOLVED_STATUS ):
@@ -1740,20 +1743,19 @@ def process_resolution_from_jira(finding, resolution_id, resolution_name, assign
1740
1743
1741
1744
def save_and_push_to_jira (finding ):
1742
1745
# Manage the jira status changes
1743
- push_to_jira = False
1746
+ push_to_jira_decision = False
1744
1747
# Determine if the finding is in a group. if so, not push to jira yet
1745
1748
finding_in_group = finding .has_finding_group
1746
1749
# Check if there is a jira issue that needs to be updated
1747
1750
jira_issue_exists = finding .has_jira_issue or (finding .finding_group and finding .finding_group .has_jira_issue )
1748
1751
# Only push if the finding is not in a group
1749
1752
if jira_issue_exists :
1750
1753
# Determine if any automatic sync should occur
1751
- push_to_jira = is_push_all_issues (finding ) \
1754
+ push_to_jira_decision = is_push_all_issues (finding ) \
1752
1755
or get_jira_instance (finding ).finding_jira_sync
1753
1756
# Save the finding
1754
- finding .save (push_to_jira = (push_to_jira and not finding_in_group ))
1755
-
1757
+ finding .save (push_to_jira = (push_to_jira_decision and not finding_in_group ))
1756
1758
# we only push the group after saving the finding to make sure
1757
1759
# the updated data of the finding is pushed as part of the group
1758
- if push_to_jira and finding_in_group :
1760
+ if push_to_jira_decision and finding_in_group :
1759
1761
push_to_jira (finding .finding_group )
0 commit comments