suever / pydicom-experimental

pydicom test
0 stars 1 forks source link

SQ VR Assignment accepts any input #111

Closed suever closed 9 years ago

suever commented 9 years ago

From Suever@gmail.com on February 10, 2012 10:42:37

When assigning a value to a DataElement with a VR of 'SQ', there is no validation to ensure that it is actually a Sequence. Instead, it quietly accepts the assignment, but then exhibits strange behavior:

from dicom.dataset import Dataset d = Dataset() d.BeamSequence = [1,2,3] d Traceback (most recent call last): File "", line 1, in File "dicom/dataset.py", line 536, in str return self._PrettyStr() File "dicom/dataset.py", line 465, in _PrettyStr strings.append(dataset._PrettyStr(indent+1)) AttributeError: 'int' object has no attribute '_PrettyStr'

Obviously, [1,2,3] is not a valid sequence, but was accepted regardless; however, attributes and methods of Sequence are necessary

Correct behavior should be:

from dicom.dataset import Dataset from dicom.sequence import Sequence d = Dataset() d.BeamSequence = Sequence() d (300a, 00b0) Beam Sequence 0 item(s) ----

I've attached a patch for dataelem that checks that the input is a Sequence or attempts to convert it to a Sequence if possible.

If using Dataset.add_new() to add DataElements, you actually had to specify the VR, so it was ok to make the user provide a valid input; however with dot assignment (shown above), it could be a little misleading because you aren't specifying the VR explicitly.

Attachment: dataelem.diff

Original issue: http://code.google.com/p/pydicom/issues/detail?id=111

suever commented 9 years ago

From darcymason@gmail.com on February 11, 2012 14:22:37

This issue was closed by revision fb1893e4574c .

Status: Fixed