Scene load broken due to new volume unit attribute

py_SubjectHierarchyGenericSelfTest started failing due to a failure of loading a scene. Digging into it, this error message (Error parsing XML in stream at line 38, column 151, byte index 10406: not well-formed (invalid token)) points to this line:

  id="vtkMRMLScalarVolumeNode1" name="303: Unnamed Series" hideFromEditors="false" selectable="true" selected="false" attributes="DICOM.QuantityCode:{"CodeMeaning": "Attenuation Coefficient", "CodingSchemeDesignator": "DCM", "CodeValue": "110852"};DICOM.UnitsCode:{"CodeMeaning": "Hounsfield unit", "CodingSchemeDesignator": "UCUM", "CodeValue": "[hnsf'U]"};DICOM.instanceUIDs:1.2.826.0.1.3680043. 1.2.826.0.1.3680043. 1.2.826.0.1.3680043. 1.2.826.0.1.3680043. 1.2.826.0.1.3680043. 1.2.826.0.1.3680043. 1.2.826.0.1.3680043. 1.2.826.0.1.3680043. 1.2.826.0.1.3680043. 1.2.826.0.1.3680043." displayNodeRef="vtkMRMLScalarVolumeDisplayNode1" references="display:vtkMRMLScalarVolumeDisplayNode1;" userTags="" ijkToRASDirections="-1   0   0 0   -1   0 0 0 1 " spacing="49 49 23" origin="248.844 248.289 -123.75" ></Volume>

Specifically the quotation mark before “CodeMeaning”. As this attribute is added when loading a volume from DICOM, I suspect that now all saved scenes are invalid that contain a DICOM volume. It would be good either to revert this commit
while fixing this, or fixing this quickly.

I’ll take care of this by this information into a member variable. We could encode the attribute to be able to store special characters, such as ", but we’ll use the unit for many things, so it’s better not to store it in just a generic metadata.

Scene corruption is a serious error that our development process should have captured. The pull request was open for a few days but just by looking at the code nobody noticed the error. SH test did capture the error (see failed test this morning, it even showed the relevant error message on the dashboard “Error parsing XML in stream at line 38, column 151, byte index 10404: not well-formed (invalid token)”) and the dashboard is normally green (we don’t have any failing test), so it should not be too difficult to spot new errors.
@jcfr do you know why the tests were not executed automatically by the pull request (
@Fedorov do you remember if you’ve run the automatic tests manually and if you saw the new test failure?

Sorry for the trouble guys. I admit I did not run the tests manually, so it is my fault!

@lassoan will you implement the solution you mentioned, or should I revert the commit?

Definitively, storing a complex document (e.g json) as a MRML attribute is a stretch.

Tests are not yet run automatically, we need to finalize integration of the work of Mayeul. For now, it is only the build.

As soon as this is enabled, we will capture such regression beforehand.

I revert the commit now and implement member variable storage within a few hours.


Thanks @lassoan for tackling this.

On my side, I will look into adding the testing to the PR later this week

Reverted in rev r26176.

Thanks guys!

Do you think it would be worth sanitizing an attribute when setting (and restoring it when getting)? Users might add attributes with quotation marks and they might wonder what broke. Not sure if simply escaping the quotation mark would solve this, but if it does, then it’s a very simple solution.

Yes, currently special characters in any node properties (name, description, attributes, …) can lead to invalid scenes - see There is a function in MRML node already for encoding/decoding, we could probably use that in read/write XML of MRML node to fix this.

1 Like