Issue 111 in pydicom: SQ VR Assignment accepts any input

1 view
Skip to first unread message

pyd...@googlecode.com

unread,
Feb 10, 2012, 10:43:41 AM2/10/12
to pydic...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium Difficulty-Medium

New issue 111 by Suever: SQ VR Assignment accepts any input
http://code.google.com/p/pydicom/issues/detail?id=111

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.

Attachments:
dataelem.diff 705 bytes

pyd...@googlecode.com

unread,
Feb 11, 2012, 5:27:30 PM2/11/12
to pydic...@googlegroups.com
Updates:
Status: Fixed

Comment #1 on issue 111 by darcy...@gmail.com: SQ VR Assignment accepts
any input
http://code.google.com/p/pydicom/issues/detail?id=111

This issue was closed by revision fb1893e4574c.

Reply all
Reply to author
Forward
0 new messages