question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicate ID in model error during update if parent is changed

See original GitHub issue

I have the following simplified model:

  • currentRoot
    • Element A (id XXXX)
    • Element B (id XXXX)
      • Element C (id 96f958fb-d59f-45c4-ae19-c80289d65bff_Block) which is set in the LocalModelSource. Calling “updateModel()” displays the model fine.

I have a operation which removes the hierarchy and produces a flat version of the model which is then set as “currentRoot”. The new model looks like this:

  • currentRoot
    • Element A (id XXXX)
    • Element B (id XXXX)
    • Element C (id 96f958fb-d59f-45c4-ae19-c80289d65bff_Block)

Winn update is called i get the following error:

sprotty CommandStack: Failed to execute command: Error: Duplicate ID in model: 96f958fb-d59f-45c4-ae19-c80289d65bff_Block
    at SGraphIndex../node_modules/sprotty/lib/base/model/smodel.js.SModelIndex.add (smodel.ts:224)
    at SGraphIndex../node_modules/sprotty/lib/graph/sgraph.js.SGraphIndex.add (sgraph.ts:191)
    at SGraphIndex../node_modules/sprotty/lib/base/model/smodel.js.SModelIndex.add (smodel.ts:229)
    at SGraphIndex../node_modules/sprotty/lib/graph/sgraph.js.SGraphIndex.add (sgraph.ts:191)
    at SGraph../node_modules/sprotty/lib/base/model/smodel.js.SParentElement.add (smodel.ts:103)
    at update-model.ts:184
    at Object.forEachMatch (model-matching.ts:33)
    at UpdateModelCommand../node_modules/sprotty/lib/features/update/update-model.js.UpdateModelCommand.computeAnimation (update-model.ts:162)
    at UpdateModelCommand../node_modules/sprotty/lib/features/update/update-model.js.UpdateModelCommand.performUpdate (update-model.ts:100)
    at UpdateModelCommand../node_modules/sprotty/lib/features/update/update-model.js.UpdateModelCommand.execute (update-model.ts:88)

Current workaround is something like this at the moment (which is bad because it adds an additional command on stack which needs to be undone):

this.currentRoot.children = [];
await super.updateModel();
this.currentRoot.children = [flat model];

As it looks like the update implementation tries to add the Element C in currentRoot before removing it from Element B first.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
BjBe82commented, Aug 20, 2021

I can confirm that the fix solves the issue.

1reaction
spoenemanncommented, Feb 22, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

updating child entity in parent entity gives duplicate violation ...
What I mean is that use MasterSectionName for updating the db, then fetch the updated data with included correct values and then serialize...
Read more >
Preventing System.ListException: Duplicate id in list
I have a trigger that is a bulk update. Sometimes the same object will make it into my update list more than once,...
Read more >
how to solve this "System.ListException: Duplicate id in list in ...
1) Copy the List lstUpdateParent of Products to another SET or MAP (which do not allow the Duplicates). 2) If you copy the...
Read more >
Parent/Child Hierarchy with duplicates in Employee ID
If ID_columnName has duplicates and parent_columnName is the same for those duplicates then PATH() returns the common parent_columnName value; however, if ...
Read more >
Why do i get duplicate entries on the failed events view ... - IBM
This could happen, when you have 2 events fail at the same timebecause of a processing error like "no parent found error". Because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found