Scriptrunner delete subtasks showing indexing errors after upgrading from jira Server 7.x to 8.13.3.

Montana Fox August 16, 2021

We recently upgraded our Jira Server instance from 7.2.7 with Scriptrunner 5.4.28, and are now using Jira Server 8.13.3 with Scriptrunner 6.27.0.

I have a scripted post-function which deletes all subtasks of the current issue. This post function performed without any problems in the old instance. Since upgrading, it still works, but now it displays an indexing error.

com.atlassian.jira.index.IndexingFailureException: Indexing completed with 1 errors

The number of errors matches the number of subtasks it deleted. (1 subtask, 1 error. 5 subtasks, 5 errors.) There is a HUGE wall of log text following this line, which I will not bother to paste here.

The code I've been using for the post-function is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
// for JIRA v6.*
def user = ComponentAccessor.getJiraAuthenticationContext().user.directoryUser
// for JIRA v7.*
// def user = ComponentAccessor.getJiraAuthenticationContext().user
def issueManager = ComponentAccessor.getIssueManager()
// will return a Collection<Issue> with all the subtasks of the current issue
def subTasksList = issue.getSubTaskObjects()
for (subTask in subTasksList) {
    // add a condition here if you DO NOT want to delete all the sub-tasks
    issueManager.deleteIssue(user, subTask, EventDispatchOption.ISSUE_DELETED, false)
}

Are my errors showing up because I'm in a newer version of Jira, or because I'm using a newer version of Scriptrunner, or both?

Is there a newer version of this code that I can use which will properly perform the delete without the errors?

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 16, 2021

It might be helpful to see the first 5-10 lines of the stack trace.

But I know that to get the current user, I use the following:

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

This also works (but groovy lets you omit the get keywords and that's my preference):

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

The "getUser()" method is still available but is flagged as deprecated. 

The deleteIssue() method expects an ApplicationUser and your current code is returning a com.atlassian.crowd.embedded.api.User. So that might be the issue. 

Montana Fox August 19, 2021

I was really hopeful that your suggestion would work, but unfortunately no. Here's what my current code looks like. Still getting the same results: successful transition, but error message.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def issueManager = ComponentAccessor.issueManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// Get a list of the current issue's subtasks
def subtasks = issue.getSubTaskObjects()

// Loop through all the subtasks and delete them
subtasks.each {
issueManager.deleteIssue(currentUser, it, EventDispatchOption.ISSUE_DELETED, false)
}
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2021

Can you include the first 10 lines of the errors message (or so).

That should give us some hints.

Montana Fox August 19, 2021

Here are the first 15 lines of the warning message. There are 287 lines total.

com.atlassian.jira.index.IndexingFailureException: Indexing completed with 5 errors
at com.atlassian.jira.index.AccumulatingResultBuilder$CompositeResult.await(AccumulatingResultBuilder.java:189) [classes/:?]
at com.atlassian.jira.issue.index.DefaultIndexManager.obtain(DefaultIndexManager.java:863) [classes/:?]
at com.atlassian.jira.issue.index.DefaultIndexManager.await(DefaultIndexManager.java:843) [classes/:?]
at com.atlassian.jira.issue.index.DefaultIndexManager.executeWithIndexLock(DefaultIndexManager.java:830) [classes/:?]
at com.atlassian.jira.issue.index.DefaultIndexManager.reIndexIssues(DefaultIndexManager.java:618) [classes/:?]
at com.atlassian.jira.issue.index.DefaultIndexManager.reIndexIssues(DefaultIndexManager.java:597) [classes/:?]
at com.atlassian.jira.issue.index.DefaultIndexManager.reIndexIssues(DefaultIndexManager.java:581) [classes/:?]
at com.atlassian.jira.issue.index.DefaultIndexManager.release(DefaultIndexManager.java:570) [classes/:?]
at sun.reflect.GeneratedMethodAccessor3407.invoke(Unknown Source) [?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [?:1.8.0_275]
at java.lang.reflect.Method.invoke(Method.java:498) [?:1.8.0_275]
at com.atlassian.jira.config.component.SwitchingInvocationHandler.invoke(SwitchingInvocationHandler.java:38) [classes/:?]
at com.sun.proxy.$Proxy17.release(Unknown Source) [?:?]
at com.atlassian.jira.workflow.OSWorkflowManager.enableIndexingForThisThread(OSWorkflowManager.java:926) [classes/:?]
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2021

Try to use IssueService instead of IssueManager. It is better at managing the indexing.

def validationResult = issueService.validateDelete(currentUser, subTask.id)
if(validationResult.isValid()){
   issueSevice.delete(currentUser, validationResult, EventDispatchOption.ISSUE_DELETED, false)

Another option might be to manually de-index the subtask.

Montana Fox August 19, 2021

No luck.

Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2021

Sorry... I have nothing more to suggest.

I'm not convinced these errors are linked to the post function script.

I'd try a full locked reindex.

Arianna Fabbri
Contributor
January 19, 2022

Hi @Montana Fox , have you found a solution to this issue?

Thank you

Montana Fox January 19, 2022

YES! They finally provided an updated script!

Here is the support issue they created for the problem: SRJIRA-5636 

And here is the new code they posted: Deleting all subtasks of an issue 

I have tested this new script and it works perfectly.

TAGS
AUG Leaders

Atlassian Community Events