Kiyokawa / pydicom

Automatically exported from code.google.com/p/pydicom
0 stars 0 forks source link

SQ VR Assignment accepts any input #111

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

Attachments:

GoogleCodeExporter commented 8 years ago
This issue was closed by revision fb1893e4574c.

Original comment by darcymason@gmail.com on 11 Feb 2012 at 10:22