-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Hi,
I just took 2 hours debugging a weird behavior, I could nail down to different Components instances sharing attribute models.
You can reproduce it like this:
Open an simple Ruby console, require "draco.rb" and run this code:
class A < Draco::Component
attribute :list, default: []
end
class B < Draco::Entity
component A
end
class C < Draco::Entity
component A
end
b1 = B.new
b2 = B.new
c = C.new
puts b1.a.list.object_id
puts b2.a.list.object_id
puts c.a.list.object_id
puts b1.a.list == b2.a.list
puts b1.a.list == c.a.listthe list object in instances b1, b2 and c is the same.
Adding something to the list in b1.a will have it added in c.a
b.a.list << "Example"
#=> ["Example"]
c.a.list
#=> ["Example"]The same happens on other types, like a Hash.
I'm working around this now by using Entity#after_initialize like this:
class B < Draco::Entity
component :A
def after_initialize
a.list = []
end
endIs this expected behavior or a bug? I got caught by surprise.
Regards,
Dahie
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels