# Calls to CLI makes tests to fail

**URL:** <https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835>\
**Category:** Development\
**Tags:** cli\
**Created:** [October 3, 2020, 3:18am UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835 "2020-10-03T03:18:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [October 3, 2020, 3:18am UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/1 "2020-10-03T03:18:49Z")

</div>

In my module I have some calls to Slicer CLI scripts, like brainsresample. In my code I do

```auto
parameters = {'inputVolume': nodeCT.data, 'referenceVolume': nodeSPECT.data, 'outputVolume': CTRSNode,
              'interpolationMode': 'Lanczos', 'defaultValue': minCT}
slicer.cli.run(slicer.modules.brainsresample,
               None, parameters, wait_for_completion=True, update_display=False)

```

This makes the [test fail](http://slicer.cdash.org/testDetails.php?test=10161333&build=2026803) ith this error

```auto
======================================================================
ERROR: runTest (Dosimetry4DTest.Dosimetry4DTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Volumes/D/P/S-0-E-b/OpenDose3D/Dosimetry4D/Logic/Dosimetry4DTest.py", line 79, in runTest
    self.FullTest_positive()
  File "/Volumes/D/P/S-0-E-b/OpenDose3D/Dosimetry4D/Logic/Dosimetry4DTest.py", line 484, in FullTest_positive
    self.logic.resampleCT()
  File "/Volumes/D/P/S-0-E-b/OpenDose3D-build/lib/Slicer-4.13/qt-scripted-modules/Logic/Dosimetry4DLogic.py", line 601, in resampleCT
    None, parameters, wait_for_completion=True, update_display=False)
  File "/Volumes/D/P/S-0-build/Slicer-build/bin/Python/slicer/cli.py", line 72, in run
    node = createNode(module, parameters)
  File "/Volumes/D/P/S-0-build/Slicer-build/bin/Python/slicer/cli.py", line 13, in createNode
    node = cliLogic.CreateNodeInScene()
AttributeError: 'SlicerBaseLogic.vtkSlicerModuleLogic' object has no attribute 'CreateNodeInScene'

----------------------------------------------------------------------

```

Has something changed in `cli.py` or in the `cliLogic`?

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [October 3, 2020, 12:58pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/2 "2020-10-03T12:58:35Z")

</div>

Note that if this error just recently happened it is probably due to the update of the preview build to use VTK9. So there’s likelihood of a lot of underlying issues since VTK is a core dependency. Things will stabilize over the next week or more.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [October 4, 2020, 5:31pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/3 "2020-10-04T17:31:46Z")

</div>

if it helps this is the line that raises the exceptions [https://github.com/Slicer/Slicer/blob/0b1560371fa1ad1bc0d87f42004353e66f583535/Libs/MRML/Core/vtkMRMLScene.cxx#L314](https://github.com/Slicer/Slicer/blob/0b1560371fa1ad1bc0d87f42004353e66f583535/Libs/MRML/Core/vtkMRMLScene.cxx#L314)

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [October 8, 2020, 12:53pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/4 "2020-10-08T12:53:41Z")

</div>

Recently [I have reported](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835) some test failing in CDash.

The main error is

```auto
======================================================================
ERROR: runTest (Dosimetry4DTest.Dosimetry4DTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Volumes/D/P/S-0-E-b/OpenDose3D/Dosimetry4D/Logic/Dosimetry4DTest.py", line 79, in runTest
    self.FullTest_positive()
  File "/Volumes/D/P/S-0-E-b/OpenDose3D/Dosimetry4D/Logic/Dosimetry4DTest.py", line 484, in FullTest_positive
    self.logic.resampleCT()
  File "/Volumes/D/P/S-0-E-b/OpenDose3D-build/lib/Slicer-4.13/qt-scripted-modules/Logic/Dosimetry4DLogic.py", line 614, in resampleCT
    None, parameters, wait_for_completion=True, update_display=False)
  File "/Volumes/D/P/S-0-build/Slicer-build/bin/Python/slicer/cli.py", line 72, in run
    node = createNode(module, parameters)
  File "/Volumes/D/P/S-0-build/Slicer-build/bin/Python/slicer/cli.py", line 13, in createNode
    node = cliLogic.CreateNodeInScene()
AttributeError: 'SlicerBaseLogic.vtkSlicerModuleLogic' object has no attribute 'CreateNodeInScene'

----------------------------------------------------------------------

```

Digging a little in Slicer code I found that indeed there is no ‘CreateNodeInScene’ attribute inside ‘SlicerBaseLogic.vtkSlicerModuleLogic’, but it exists inside ‘SlicerBaseLogic.vtkSlicerCLIModuleLogic’. The first is abstract class now and the second inherits from the first. Somehow the cli is losing the concrete class and it is using the abstract one.

Has somebody else noticed this behaviour?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 8, 2020, 1:04pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/5 "2020-10-08T13:04:48Z")

</div>

This works well for me:

```python
cliModule = slicer.modules.resamplescalarvolume
cliLogic = cliModule.logic()
parameterNode = cliLogic.CreateNodeInScene()
print(parameterNode)

```

Can you provide a minimal example that reproduces the problem you have?

Typically if Python cannot find a specific class (and returns a class at a higher level in the hierarchy) if the Python module is not imported. You may need to do something like `import vtkSomeLibraryPython` before you try to access a class defined in `SomeLibrary`. Normally this import happens automatically for all modules that follow conventions but maybe you do something special or something broke in Slicer.

If you experience this in latest Slicer master then enter a bug report and we’ll get to it when other VTK upgrade related errors are fixed.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [October 8, 2020, 1:49pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/6 "2020-10-08T13:49:04Z")

</div>

It works well for me too in Slicer directly and even in my Docker image pre VTK change. It only raises this exception in the CDash build system.

Maybe I shall create a more recent Docker image to test.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [October 9, 2020, 2:06pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/7 "2020-10-09T14:06:11Z")

</div>

> [@Alex\_Vergara](#):
>
> Maybe I shall create a more recent Docker image to test.

The new Docker version (bishopwolf/slicer3d-nightly:0.4.2) still behaves normally, these errors are not showing. I don’t know how to reproduce the problem. But it is still present in CDash.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [October 10, 2020, 6:43pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/8 "2020-10-10T18:43:44Z")

</div>

Tried with home made Slicer in Manjaro with qt 5.15.1. No test failed. I am out of options to try to replicate the CDash errors.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 10, 2020, 6:50pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/9 "2020-10-10T18:50:30Z")

</div>

I could reproduce the problem on Windows by simply building a latest Slicer master version. We’ll get to it after we fixed more urgent issues (e.g., image not appearing in slice views).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 11, 2020, 2:45am UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/10 "2020-10-11T02:45:57Z")

</div>

Using Slicer-4.11.20200930:

```nohighlight
>>> slicer.vtkSlicerCLIModuleLogic()
(qSlicerBaseQTCLIPython.vtkSlicerCLIModuleLogic)00000167BA933648

```

Using latest master:

```nohighlight
>>> slicer.vtkSlicerCLIModuleLogic()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: this class cannot be instantiated

```

I’ve debugged into wrappython.exe and the problem is that for some reason the hierarchy cannot find the parent’s class in the hierarchy and so it determines that vtkSlicerCLIModuleLogic is not a VTK class, therefore it looks for a public constructor (instead of `New()`), which is of course is not found. @jcfr I guess you know what’s going on. Could you have a look?

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [October 25, 2020, 6:49pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/11 "2020-10-25T18:49:16Z")

</div>

Any news on this? I am still getting these errors in CDash

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 25, 2020, 9:07pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/12 "2020-10-25T21:07:55Z")

</div>

We still have higher-priority issues to fix in Slicer-4.13, but I’ve added a ticket to ensure that it gets fixed: [https://github.com/Slicer/Slicer/issues/5266](https://github.com/Slicer/Slicer/issues/5266)

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [November 12, 2020, 2:29pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/13 "2020-11-12T14:29:14Z")

</div>

In the [last CDash](http://slicer.cdash.org/index.php?project=SlicerPreview&date=2020-11-12&filtercount=1&showfilters=1&field1=buildname&compare1=63&value1=Opendose) this issue appears to be solved

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 12, 2020, 2:34pm UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/14 "2020-11-12T14:34:05Z")

</div>

The issue probably has not been resolved yet, we just switched back temporarily to VTK8 in factory builds due to this and other problems. Keep discussion at [https://github.com/Slicer/Slicer/issues/5266](https://github.com/Slicer/Slicer/issues/5266) to avoid parallel discussion of the same issue at two places.

---

<div class="post-metadata">

**Author:** ![gaoyi.cn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gaoyi.cn/32/1422_2.png) [@gaoyi.cn](https://discourse.slicer.org/u/gaoyi.cn)\
**Post date:** [February 4, 2021, 11:51am UTC](https://discourse.slicer.org/t/calls-to-cli-makes-tests-to-fail/13835/15 "2021-02-04T11:51:14Z")

</div>

I had the same issue: calling cli.run gives the error.  
and i confirm that reverting to VTK8 solves the problem.
