Cannot 'undo' if updateProperties is called in .added event handler

I don’t know if I’m doing something wrong, or if it’s a bug.

Given a event handler for ‘connection.added’ similar to the one below,

    eventBus.on('connection.added', function (event) {
      var target =;
      if (!is(target, 'bpmn:Gateway')) {

      modeling.updateProperties(target, { gatewayDirection: 'Converging' });

and a BPMN flow A->B->C where C is a gateway.
When performing a undo after having removed B, an error is produced

Error: element with id SequenceFlow_2 already exists

Failing test is available here
(tip commit

Hello @adbre,

I’ve added an issue regarding this. The way to solve your issue is by adding the listener to connection.added.postExecute, because during execute or revert there shouldn’t be any modeling actions being performed or the execution chain will break. During these phases only atomic actions should be performed. What happens here is that during revert the connection.added is being fired and therefore it’s trying to add SequenceFlow_2 twice.


Thanks! But there is no connection.added.postExecute event.
But there are several commandStack.X.postExecute:slightly_smiling:

Good catch and yes, that is the idea.

You cannot invoke other modeling operations in the atomic execute and revert phases. You can hook into the respective preExecute or postExecute phases though in order to do your magic.

We are going to improve this by throwing an error indicating that (via bpmn-io/bpmn-js#143).