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

SpineInterface can create duplicate Objects that causes some confusion. #81

Open
Tasqu opened this issue Mar 30, 2022 · 1 comment
Open
Labels
bug Something isn't working

Comments

@Tasqu
Copy link
Member

Tasqu commented Mar 30, 2022

Essentially, it seems that the Object constructor creates a duplicate Object, that fools some of the code into thinking that the Object is the same as one already in the database, while other functionality recognises that there's a difference. For example, when loading a database into memory with a building_archetype ObjectClass with an Object called IDA_ESBO_AB:

julia> ba1 = building_archetype(:IDA_ESBO_AB)
julia> ba2 = Object(:IDA_ESBO_AB, :building_archetype)
julia> ba1 == ba2
julia> true

but

julia> ba1 === ba2
julia> false

Furthermore, if comparing the fields of the Objects:

julia> [getfield(ba, field) for field in fieldnames(typeof(ba))] .== [getfield(ba2, field) for field in fieldnames(typeof(ba2))]
5-element BitVector:
 1
 1
 0
 1
 1

and

julia> [getfield(ba, field) for field in fieldnames(typeof(ba))] .=== [getfield(ba2, field) for field in fieldnames(typeof(ba2))]
5-element BitVector:
 1
 1
 0
 0
 1

where

julia> fieldnames(typeof(ba))
(:name, :class_name, :members, :groups, :id)

I believe that spinedb_api doesn't allow duplicate objects inside the same object class, so we should probably fix the Object constructor so that it either throws an error when trying to create a duplicate object, or refers to the pre-existing object instead.

@Tasqu Tasqu added the bug Something isn't working label Mar 30, 2022
@Tasqu
Copy link
Member Author

Tasqu commented Mar 30, 2022

Well, it turns out that this is a pretty fundamental problem. The easiest way would be to simply prevent users from creating Objects that already exist, e.g. by checking their database ids. Otherwise, we start running into issues about what the user tries to do with the Object constructor. However, I'm not sure a change like this wouldn't mess something up.

E.g. how should the Object constructor handle a situation where there already exists an object with a given name, class_name, members, groups, and id, and the user uses the Object constructor to create a new object with the exact same name and class_name, but different members and groups? Should SpineInterface interpret this as an attempt to update the existing Object, or an attempt to create a new Object? And if the name and object_class are identical, how are the Objects distinguished from one another?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant