Calls to CLI makes tests to fail

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

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 ith this error

======================================================================
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?

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.

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

Recently I have reported some test failing in CDash.

The main error is

======================================================================
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?

This works well for me:

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.

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.

1 Like

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.

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.

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).

Using Slicer-4.11.20200930:

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

Using latest master:

>>> 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?

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

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

1 Like

In the last CDash this issue appears to be solved

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 to avoid parallel discussion of the same issue at two places.

1 Like

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