Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sbol3/refobj_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ def to_user(self, value: Any) -> str:
@staticmethod
def from_user(value: Any) -> rdflib.URIRef:
if isinstance(value, SBOLObject):
# see https://github.com/SynBioDex/pySBOL3/issues/357
if value.identity is None:
# The SBOLObject has an uninitialized identity
msg = f'Cannot set reference to {value}.'
msg += ' Object identity is uninitialized.'
raise ValueError(msg)
value = value.identity
if not isinstance(value, str):
raise TypeError(f'Expecting string, got {type(value)}')
Expand Down
9 changes: 9 additions & 0 deletions test/test_referenced_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ def test_adding_referenced_objects(self):
# to get back to the original instance via document lookup
self.assertEqual(execution.identity, foo.members[0].lookup().identity)

def test_no_identity_exception(self):
# See https://github.com/SynBioDex/pySBOL3/issues/357
sbol3.set_namespace('https://github.com/SynBioDex/pySBOL3')
collection = sbol3.Collection('foo_collection')
subc = sbol3.SubComponent(instance_of='https://github.com/SynBioDex/pySBOL3/c1')
exc_regex = r'Object identity is uninitialized\.$'
with self.assertRaisesRegex(ValueError, exc_regex):
collection.members.append(subc)


if __name__ == '__main__':
unittest.main()