Uploaded image for project: 'Jira Service Management Data Center'
  1. Jira Service Management Data Center
  2. JSDSERVER-12676

ValidationInsightException when updating object attributes with unique values

    XMLWordPrintable

Details

    Description

      Issue Summary

      Issue only occurs after Jira 9.x

      When using Groovy scripts to update object attributes with unique values, if the script is ran multiple times in short period of time, there is an "ValidationInsightException" message.

      This is reproducible on Data Center: yes

      Steps to Reproduce

      1. Go to Administration > Manage Apps > Assets Script Console > and paste the following script:
        import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
        import com.atlassian.jira.component.ComponentAccessor;
        import org.apache.log4j.Logger
        import org.apache.log4j.Level
        
        Logger log = Logger.getLogger("test")
        log.setLevel(Level.ALL)
        
        
        
        
        void storeObjectAttributes(ObjectBean objectBean, Integer attributeId, String... values) {
        
            Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade");  
            def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass);
            Class objectTypeAttributeFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade"); 
            def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectTypeAttributeFacadeClass);
            Class objectAttributeBeanFactoryClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory");
            def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(objectAttributeBeanFactoryClass);
        
            log.info("Object: $objectBean")
            def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttribute(attributeId).createMutable()
            log.info("\tobjectTypeAttributeBean: $objectTypeAttributeBean")
            def objectAttributeBean = objectFacade.loadObjectAttributeBean(objectBean.getId(), objectTypeAttributeBean.getId())
            log.info("\tobjectAttributeBean: $objectAttributeBean")
            log.info("Value: $values")
            def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(objectBean, objectTypeAttributeBean, values)
         
            if (objectAttributeBean != null) {
                newObjectAttributeBean.setId(objectAttributeBean.getId())
            }
            objectFacade.storeObjectAttributeBean(newObjectAttributeBean)
            log.info("\tSuccess: Object updated")
            
        
        }
        
        storeObjectAttributes(object, 5, 10092 as String)
        storeObjectAttributes(object, 5, 10092 as String)
        //storeObjectAttributes(object, 5, 10092 as String)
        //storeObjectAttributes(object, 5, 10092 as String)
        
      1. You need to provide a valid Object Key in the Object Key field in Insight Script Console and pass appropriate input params attribute id and attribute value.
        • Note: attribute that you update should have unique value constraint.
        • In this example, attribute the attribute I want to updated has an attribute id 5 and it requires unique value.
      2. In "Object Key" field from the Groovy console, add the object to be updated
      3. While running the script, you could either invoke the function multiple times or click run button in script console multiple times to reproduce the issue.

      Expected Results

      Object should be updated without any error.

      Actual Results

      The below exception is thrown in the atlassian.log file:

      2023-04-24 12:19:23,585+0000 http-nio-8080-exec-27 url: /rest/insight/1.0/groovy/evaluate; user: admin DEBUG admin 739x7793x2 6zkla5 xxxx /rest/insight/1.0/groovy/evaluate [c.r.j.p.i.services.validation.ValidateObjectImpl] Unique check: Concurrent modification occurred on attribute 5
      2023-04-24 12:19:23,585+0000 http-nio-8080-exec-27 url: /rest/insight/1.0/groovy/evaluate; user: admin INFO admin 739x7793x2 6zkla5 xx /rest/insight/1.0/groovy/evaluate [c.r.j.p.i.services.util.ServiceUtil] InsightException:ValidationInsightException: Validation errors were found: rlabs-insight-attribute-5: ErrorMessage{i18nKey='rlabs.insight.i18n.constraint.violation.unique', parameters=[Worklog], additionalMessage=null};
      com.riadalabs.jira.plugins.insight.common.exception.ValidationInsightException: ValidationInsightException: Validation errors were found: rlabs-insight-attribute-5: ErrorMessage{i18nKey='rlabs.insight.i18n.constraint.violation.unique', parameters=[Worklog], additionalMessage=null};
      	at com.riadalabs.jira.plugins.insight.services.validation.ValidateObjectImpl.validateObjectAttributeBean(ValidateObjectImpl.java:153)
      	at com.riadalabs.jira.plugins.insight.services.core.ObjectServiceImpl.storeObjectAttribute(ObjectServiceImpl.java:1158)
      	at com.riadalabs.jira.plugins.insight.channel.external.api.facade.impl.ObjectFacadeImpl.storeObjectAttributeBean(ObjectFacadeImpl.java:119)
      	at com.riadalabs.jira.plugins.insight.channel.external.api.facade.impl.ObjectFacadeImpl.storeObjectAttributeBean(ObjectFacadeImpl.java:112)
      	at com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade$storeObjectAttributeBean$0.call(Unknown Source)
      	at Script1.storeObjectAttributes(Script1.groovy:30)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:157)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185)
      	at Script1.run(Script1.groovy:37)
      {code}
      

      Workaround

      Currently there is no known workaround for this behavior. A workaround will be added here when available

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              9f03f4114502 Pablo Bartolome
              Votes:
              4 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Backbone Issue Sync