Custom field is not updated properly every time

Gergo Papp October 2, 2019

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:

  1. the user starts a transition that leads to the same status as it started
  2. the first post function of the transition set a custom field to a fixed value (in progress)
  3. the last post function of the transition initiates a longer action that is moved to a new thread in order to avoid unresponsive UI
  4. in the end of the aforementioned action, the same custom field is set to any of two predefined values based on the result of the action (either succeeded, or failed)
  5. an attachment is added to the issue

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:

  1. installed the plugin,
  2. opened a workflow in edit mode
  3. added a transition from all status to itself
  4. added a post function (provided by other plugin) to updated a field to a fix value as a first post function of the transition
  5. added the debug post function as the last post function of the transition
  6. saved the workflow
  7. created an issue that is associated with the workflow because of its project and issue type and has the field added to its screens
  8. executed the workflow transition a couple of times

 

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

0 answers

Suggest an answer

Log in or Sign up to answer