diff --git a/backend/app/services/jira_service.py b/backend/app/services/jira_service.py index 7e0ec16..4633d0a 100644 --- a/backend/app/services/jira_service.py +++ b/backend/app/services/jira_service.py @@ -478,10 +478,22 @@ def auto_create_test_issue( try: jira = get_user_jira_client(actor, db) - # Tests nested under a campaign are Sub-tasks; standalone tests are Tasks + # Resolve parent and issue type together: + # - campaign parent override → Sub-task (Task cannot parent Task) + # - explicit standalone parent configured → Sub-task (same reason; + # the standalone parent is a Task, e.g. OFS-20798) + # - only the general parent ticket (Epic) → Task + standalone_parent = get_jira_parent_ticket_standalone(db) + general_parent = get_jira_parent_ticket(db) + parent = parent_ticket_override or standalone_parent + + has_explicit_parent = bool( + parent_ticket_override + or (standalone_parent and standalone_parent != general_parent) + ) issue_type = ( settings.JIRA_ISSUE_TYPE_SUBTASK - if parent_ticket_override + if has_explicit_parent else settings.JIRA_ISSUE_TYPE_TEST ) @@ -493,10 +505,6 @@ def auto_create_test_issue( "labels": ["aegis", "security-test", mitre_id.replace(".", "-")], } - # Use campaign ticket as parent when provided; otherwise use the - # standalone-tests parent (e.g. OFS-20798), falling back to the - # general parent ticket if the standalone one is not configured. - parent = parent_ticket_override or get_jira_parent_ticket_standalone(db) if parent: fields["parent"] = {"key": parent}