Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an object to more than one parent Document #416

Open
bbartley opened this issue Nov 17, 2022 · 3 comments
Open

Adding an object to more than one parent Document #416

bbartley opened this issue Nov 17, 2022 · 3 comments

Comments

@bbartley
Copy link
Contributor

If you try to share the same object across multiple Documents, you can get into trouble. I stumbled upon this problem because I was trying to re-use an Agent object (representing a lab robot) in multiple Documents. How should pysbol3 handle this scenario?

a = sbol3.Agent('lab_robot')
doc1 = sbol3.Document()
doc2 = sbol3.Document()
doc1.add(a)
doc2.add(a)

The object now appears to be registered in both Documents:

>>> a in doc1.objects
True
>>> a in doc2.objects
True

That seems OK. However, the back-pointer to the parent doc is a problem:

>>> a.document == doc1
False
>>> a.document == doc2
True

How should pysbol3 behave? Should it throw an error/warning? Should it attempt to add a duplicate copy of the object instead?

@tcmitchell
Copy link
Collaborator

I was able to repeat your example. Thanks for the very clear report.

I do not think pysbol3 should add a duplicate copy of the object. I think that will present problems of its own. I think if you have a handle to an object, like your variable a, you expect that handle to be accurate, and be the object that is in doc2.

I suspect there is enough information present to raise an exception on the second add (doc2.add(a)) to prevent the addition. Do you think that would work for your use case? Do you think that might be problematic?

@jakebeal
Copy link
Contributor

I would support raising an exception if you try to add an object to a second document.

@bbartley
Copy link
Contributor Author

I agree that raising an exception is the appropriate behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants