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 "<stdin>", line 1, in <module>
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.
Original issue reported on code.google.com by Suever@gmail.com on 10 Feb 2012 at 3:42
Original issue reported on code.google.com by
Suever@gmail.com
on 10 Feb 2012 at 3:42Attachments: