-
Notifications
You must be signed in to change notification settings - Fork 33
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
Missing protection against duplicate id's #119
Comments
Yikes. A bit of a design flaw. Thanks @nicoweidner for pointing this out. This is probably a root cause of a few issues. The change you proposed is very logical, but as you point out it is potentially breaking since the semantics. I wonder if there may be another interface option that would preserve the existing semantics. I was thinking of using the |
One thought is to add a new constructor with different semantics and deprecate the old one. We could add a The idea behind the I have mixed feeling about whether the |
@nicoweidner I came up with another (partial) solution we could implement with low risk. If This would preserve the semantics of re-using an I'm pretty comfortable no one would intentionally create a The only case this doesn't cover is if someone accidentally creates 2 |
@goneall Given the current situation, I prefer your latest suggestion of failing when someone tries to create an object with the same id, but of different type. That should prevent all the bad scenarios, and is little effort. |
Fixed (mostly) with PR #121 |
Yet another technical issue incoming...
It is possible to create an instance of
ModelObject
using an id that is already in use. In that case, data in the model store will be untouched during instance creation, but will be changed when using the corresponding methods on the instance.As an example, let's assume that
id
is not present in the model store before the following lines:What happens is that the first line creates the corresponding
StoredTypedItem
in the model store, and the second line sets theannotator
property. The third line creates aSpdxFile
instance, but due to this part of theModelObject
constructor, nothing is changed in the model store. But the fourth line adds thecopyrightText
property, and we end up with a stored item having an inconsistent set of properties (some fromAnnotation
, some fromSpdxFile
).The only fairly quick fix I can think of is to change the semantics of the
create
boolean flag that is passed:true
, fail if an object with the given id already existsfalse
, fail if no object with the given id existsOf course, this could break a bunch of existing code, depending on how it is used.
Remark: As @armintaenzertng pointed out to me, this is also the reason that some weird examples described in #112 (review) are possible, where objects of different classes are erroneously considered equal.
The text was updated successfully, but these errors were encountered: