SynBioDex / pySBOL3

Native python implementation of SBOL 3.0 specification
MIT License
37 stars 16 forks source link

`item_added` does not update grandchild's `document` pointer #230

Closed bbartley closed 3 years ago

bbartley commented 3 years ago

When child and grandchild (?) objects are composed together, and then added to a TopLevel, the grandchild's document pointer does not get set. I believe this happens here: https://github.com/SynBioDex/pySBOL3/blob/master/sbol3/ownedobject.py#L30

Here is a minimal example:

import sbol3

class A(sbol3.CustomTopLevel):
    def __init__(self, identity, type_uri='http://example.org#A'):
        sbol3.CustomTopLevel.__init__(self, identity=identity, type_uri=type_uri)
        self.b = sbol3.OwnedObject(self, 'http://example.org#b', 0, 1)

class B(sbol3.CustomIdentified):
    def __init__(self, type_uri='http://example.org#B'):
        sbol3.CustomIdentified.__init__(self, type_uri=type_uri)
        self.c = sbol3.OwnedObject(self, 'http://example.org#c', 0, 1)

class C(sbol3.CustomIdentified):
    def __init__(self, type_uri='http://example.org#C'):
        sbol3.CustomIdentified.__init__(self, type_uri=type_uri)

# This passes
sbol3.set_namespace('http://example.org')
doc = sbol3.Document()
a = A('foo')
b = B()
c = C()
doc.add(a)
a.b = b
b.c = c
assert(c.document is not None)

# This fails because the children are composed together
# before they are added to the TopLevel
doc = sbol3.Document()
a = A('foo')
b = B()
c = C()
b.c = c
doc.add(a)
a.b = b
assert(c.document is not None)
tcmitchell commented 3 years ago

See #176, which did part of the job, but not all of the job. We should add a unit test similar to the one related to #176 so that setting the document pointer works when objects are composed before adding in addition to composition after the parent object is added to the document.