MongoMapper::Plugins::Clone.initialize_copy assumes @_id and @_id_before_type_cast are set #498

luis-ca opened this Issue Feb 4, 2013 · 3 comments


None yet

2 participants

luis-ca commented Feb 4, 2013

When cloning a document, @_id_before_type_cast is not set. Chaining clone calls will then break due to Clone trying to unset @_id_before_type_cast.

o =
o2 = o.clone
o2.clone # raises NameError: instance variable @_id_before_type_cast not defined

In fact, chaining clones produces another error

o =
o.clone.clone # raises NameError: instance variable @_id

I am not sure whether this is a problem with Clone or more interestingly, a problem with how documents are initialised.


I guess the only way it could happen is if you pass a nil id or some id that is not defaulted.

luis-ca commented Feb 4, 2013

It happens on a regular old document.

class User
    include MongoMapper::Document
end # raises NameError: instance variable @_id not defined
@cheald cheald added a commit that closed this issue Jul 6, 2013
@cheald cheald Don't remove @_id if it's not already set; this is possible since @_i…
…d is lazy-assigned on access. Closes #498.
@cheald cheald closed this in e4c7943 Jul 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment