Search code examples
bpmncamundabpmn.iocamunda-modeler

Invalid XML due to $type property


I recently updated my bpmn-js libraries to version 0.26.6. However, now that I have done so, I have ran into an issue with my diagrams.

For some reason, when parsing the diagram to XML, the SequenceFlow objects seem to have an added property, like this:

<bpmn:sequenceFlow id="SequenceFlow_0itptjk" name="x===1" sourceRef="ExclusiveGateway_16fh3h3" targetRef="Task_10pxcz5" $type="bpmn:SequenceFlow">
    <bpmn:conditionExpression language="JavaScript" xsi:type="bpmn:tFormalExpression">x===1</bpmn:conditionExpression>
</bpmn:sequenceFlow>

The problem is that the $type="bpmn:SequenceFlow" is not valid XML, and it's not passing the validations.

{
  "name": "FlowElement",
  "isAbstract": true,
  "superClass": [
    "BaseElement"
  ],
  "properties": [
    {
      "name": "name",
      "isAttr": true,
      "type": "String"
    },
    {
      "name": "auditing",
      "type": "Auditing"
    },
    {
      "name": "monitoring",
      "type": "Monitoring"
    },
    {
      "name": "categoryValueRef",
      "type": "CategoryValue",
      "isMany": true,
      "isReference": true
    }
  ]
},{
  "name": "SequenceFlow",
  "superClass": [
    "FlowElement"
  ],
  "properties": [
    {
      "name": "isImmediate",
      "isAttr": true,
      "type": "Boolean"
    },
    {
      "name": "conditionExpression",
      "type": "Expression",
      "xml": {
        "serialize": "xsi:type"
      }
    },
    {
      "name": "sourceRef",
      "type": "FlowNode",
      "isAttr": true,
      "isReference": true
    },
    {
      "name": "targetRef",
      "type": "FlowNode",
      "isAttr": true,
      "isReference": true
    }
  ]
},{
  "name": "BaseElement",
  "isAbstract": true,
  "properties": [
    {
      "name": "id",
      "isAttr": true,
      "type": "String",
      "isId": true
    },
    {
      "name": "documentation",
      "type": "Documentation",
      "isMany": true
    },
    {
      "name": "extensionDefinitions",
      "type": "ExtensionDefinition",
      "isMany": true,
      "isReference": true
    },
    {
      "name": "extensionElements",
      "type": "ExtensionElements"
    }
  ]
}

As you can see, none of those have anything that indicates why the $type is being added.

Has anyone ran into this problem in the past?

--EDIT--

After doing some testing, it seems that the $type parameter is added when a conditional expression is added to the SequenceFlow. Otherwise, the property is not added, and the XML is valid.

--EDIT2--

These are the XML definitions I am using:

<bpmn:definitions id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

--EDIT3--

A bit more details after more troubleshooting. It seems that this error is not just affecting conditional flows - it is affecting ALL types. The error happens exactly after an update, which is executed in

UpdatePropertiesHandler.prototype.execute = function(context) ...

Inside that function, there is a call to

setProperties(businessObject, properties);

Inside that set, there's this

function setProperties(businessObject, properties) {
  forEach(properties, function(value, key) {
    businessObject.set(key, value);
  });
}

After that forEach, the businessObject suddenly has a $type inside its $attrs. It's as if instead of businessObject.set, it was doing businessObject.$attr.set.


Solution

  • I found the reason for this problem. It seems that the version of bpmn-js I was using wasn't fully compatible with the camunda-moddle version that the project relies on to parse the bpmn to xml. The solution was to revert bpmn-js a version at a time until I found one that was compatible and didn't have any unexpected properties being mishandled by the camunda-moddle.