Closed bbartley closed 3 years ago
I'm about to merge a pull request that detects this situation and provides a more helpful message.
>>> import sbol3
>>> sbol3.set_namespace('https://github.com/SynBioDex/pySBOL3')
>>> collection = sbol3.Collection('foo_collection')
>>> subc = sbol3.SubComponent(instance_of='foo')
>>> collection.members.append(subc)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/bin/../../../Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/_collections_abc.py", line 962, in append
self.insert(len(self), value)
File "/Users/tmitchel/Projects/sd2/pySBOL3/sbol3/property_base.py", line 157, in insert
item = self.from_user(value)
File "/Users/tmitchel/Projects/sd2/pySBOL3/sbol3/refobj_property.py", line 40, in from_user
raise ValueError(msg)
ValueError: Cannot set reference to <sbol3.subcomponent.SubComponent object at 0x7fea400939a0>. Object identity is uninitialized.
I was debugging someone else's code, and ran into the above error message. It was difficult to figure out what was causing this error. It turns out that this error occurs when trying to set a
ReferencedObject
property using an object that does not have anidentity
. Here is a minimal test case:The error traces back to around here: https://github.com/SynBioDex/pySBOL3/blob/main/sbol3/refobj_property.py#L37
I recommend that the
from_user
method check whether the object has an identity ofNone
and fail with a more explicit message such as "Cannot set reference to object. Object identity is uninitialized."