Hello,
I'd like to ask help in regards of a strange behaviour that I encountered recently in one of the processes we have within Jira.
The simplified process looks like this:
The last 3 steps are all provided by a custom plugin, while the second one is achieved by a Script Runner simple scripted post function.
The problem that came up is this last custom field update not happens all the time, even though the attachment is attached. Which means the process is not stuck, or stopped. Based on my testing the custom field is not updated when the transition is executed twice within a relatively short time (unfortunately I cannot tell what 'relatively short' means here exactly, but it is greater than 30 seconds). As far as I can see, it is caused by the difference of the custom field value in the database, and in the application level within Java method calls. In the database the in progress value seems to be stored, in the UI the in progress is visible, however requesting the field's value in Java produce a succeeded value. And since the issue manager tries to update the field to succeeded, it does not do anything. I tried to reindex the issue, or clear the internal caches, none of them worked. Strangely setting the field to null first and setting it succeeded later worked, but resulted an unexpected issue history, like succeeded -> in progress, then succeeded -> empty, then in progress -> succeeded.
And even though the validator of the workflow transition stops the rerun of the transition if the field is set to in progress and the field is not on the edit screen, it can be edited using bulk edit, which sets the correct, selected value.
In the end I decided to reproduce the issue in a different Jira system we have with a simplified version of the original plugin. I succeeded, but the symptoms were a little different. In this case the field was not updated the first time, while the second run updated it, but the actor was anonymous instead of my user.
To summary, I did these steps:
The simplified code looks like this:
package com.ni.apps.jira.debug;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.workflow.function.issue.AbstractJiraFunctionProvider;
import com.opensymphony.module.propertyset.PropertySet;
import java.util.Map;
public class DebugPostFunction extends AbstractJiraFunctionProvider {
@Override
public void execute(Map transientVars, Map args, PropertySet propertySet) {
Thread thread = new Thread(() -> {
MutableIssue issue = getIssue(transientVars);
CustomField field = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10317L);
Option option = ComponentAccessor.getOptionsManager().findByOptionId(10607L);
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
issue.setCustomFieldValue(field, option);
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false);
});
try {
Thread.sleep(30000);
thread.start();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
The module's descriptor in atlassian-plugin.xml looks like this:
<workflow-function key="debug-post-function" name="Debug Post Function" class="com.atlassian.jira.plugin.workflow.WorkflowNoInputPluginFactory">
<description>For reproducing the problem</description>
<function-class>com.ni.apps.jira.debug.DebugPostFunction</function-class>
<resource type="velocity" name="view" location="template/view.vm"/>
<unique>true</unique>
<deletable>true</deletable>
<orderable>true</orderable>
</workflow-function>
Since I'm out of ideas what can cause the issue, I'd really appreciate any help, or ideas where should I continue my search, or how to fix the issue.
Thank you,
Gergo