# Subject hierarchy throws error message when creating item in the folder

**URL:** https://discourse.slicer.org/t/subject-hierarchy-throws-error-message-when-creating-item-in-the-folder/21815
**Category:** Development
**Created:** [February 5, 2022, 9:07pm UTC](https://discourse.slicer.org/t/subject-hierarchy-throws-error-message-when-creating-item-in-the-folder/21815 "2022-02-05T21:07:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [February 5, 2022, 9:07pm UTC](https://discourse.slicer.org/t/subject-hierarchy-throws-error-message-when-creating-item-in-the-folder/21815/1 "2022-02-05T21:07:38Z")

</div>

Hi,

I noticed that if I try to programmatically create new folder in subject hierarchy and add there a node an error message is sent. Though the node is added to the folder.  
The error message:  
**GetChildByPositionUnderParent: Failed to find subject hierarchy item under parent Scene at position 2**  
Here are the steps to reproduce:

1. open the data module (so the subject hierarchy treeview gets initialized);
2. copy/paste the code below (it creates model node, folder and adds the node to the folder):

```python
# Create and set up polydata source
box = vtk.vtkCubeSource()
box.SetXLength(30)
box.SetYLength(20)
box.SetZLength(15)
box.SetCenter(10,20,5)

# Create a model node that displays output of the source
boxNode = slicer.modules.models.logic().AddModel(box.GetOutputPort())

# Adjust display properties
boxNode.GetDisplayNode().SetColor(1,0,0)
boxNode.GetDisplayNode().SetOpacity(0.8)

#-----------------------------------------
# Subject hierarchy part starts
#-----------------------------------------
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
folderID = shNode.CreateFolderItem(shNode.GetSceneItemID(), 'MyFolder')

# On this last step check the log, an error should appear there
shNode.CreateItem(folderID, boxNode)

```

By the way there is no such error when I use GUI to create folder and drag/drop the node to the folder.

Tested on Ubuntu 20.04 with Slicer dowloaded from official site 4.13.0-2022-02-02

---

<div class="post-metadata">

### Author: ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)
#### Post date: [February 7, 2022, 2:10pm UTC](https://discourse.slicer.org/t/subject-hierarchy-throws-error-message-when-creating-item-in-the-folder/21815/2 "2022-02-07T14:10:33Z")

</div>

Unfortunately subject hierarchy sometimes logs errors that we have been unable to find the root cause for. Since there is no funding for stabilizing infrastructure (and even then, subject hierarchy has become extremely complex by now so it has a low result/effort ratio), we focus on actual bugs that arise during the common use cases. So if your code apparently works well, then I suggest ignoring this specific error.

At the same time, contributions are more than welcome to track down and fix deep infrastructure issues like this one!

---

<div class="post-metadata">

### Author: ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)
#### Post date: [February 7, 2022, 2:35pm UTC](https://discourse.slicer.org/t/subject-hierarchy-throws-error-message-when-creating-item-in-the-folder/21815/3 "2022-02-07T14:35:51Z")

</div>

Thank you, good to know
