Uploaded image for project: 'camunda BPM'
  1. camunda BPM
  2. CAM-5249

Unique constraint violation if an async start event variable is changed before job execution

    XMLWordPrintable

Details

    Description

      Problem

      If a variable is set by an async start event it is created in the runtime but not in the history as the activity instance id is unknown until the start event is executed. If this variable is changed before the start event job is executed the variable is created in the history. And when the start event job is executed another historic variable instance insert command is created. Which fails with an unique constraint violation as this historic variable instance is already created.

      Example

      BPMN Process:

      AsyncStartEventTest.testAsyncStartEventWithVariableChange.bpmn20.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <definitions id="definitions" 
        xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
        xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
        targetNamespace="Examples">
        
        <process id="testProcess">
        
          <startEvent id="start" camunda:async="true"/>
          
          <sequenceFlow id="flow" sourceRef="start" targetRef="end" />
          
          <endEvent id="end" />
          
        </process>
      
      </definitions>
      

      JUnit Test:

      @Deployment
      public void testAsyncStartEventWithVariableChange() {
        VariableMap variables = Variables.putValue("foo", "bar");
      
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testProcess", variables);
      
        Execution execution = runtimeService.createExecutionQuery().singleResult();
        runtimeService.setVariable(execution.getId(), "foo", "bar2");
      
        executeAvailableJobs();
      
        assertProcessEnded(processInstance.getId());
      }
      

      mgm-controller-panel

        This is the controller panel for Smart Panels app

        Attachments

          Activity

            People

              sebastian.menski Sebastian Menski
              sebastian.menski Sebastian Menski
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Salesforce