Create a new errors reference in dup #5958

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
3 participants
Contributor

acapilleri commented Apr 24, 2012

If an ActiveRecord instance is cloned, this keeps track of errors of this 'parent', because both errors instances point to the same ActiveModel::Errors instance. This happen when before to call dup, save or valid? is called

@carlosantoniodasilva carlosantoniodasilva and 1 other commented on an outdated diff Apr 24, 2012

activerecord/lib/active_record/base.rb
@attributes = cloned_attributes
+ @errors = cloned_errors
@carlosantoniodasilva

carlosantoniodasilva Apr 24, 2012

Owner

I think you could probably only set @errors to nil, and let the method do its job.

@acapilleri

acapilleri Apr 24, 2012

Contributor

yes, it works also and is much clear

@acapilleri

acapilleri Apr 24, 2012

Contributor

but should be better that @errors is cloned also ?

Also, I think this should be fixed in Active Model instead, because it's not only specific to Active Record, ie any class using ActiveModel::Validations would have the same possible issue not?

Contributor

acapilleri commented Apr 24, 2012

yes is specific only to ActiveRecord dup, where can I verify or apply this possible issue?

I think you just need to recreate the test under ActiveModel.

@carlosantoniodasilva carlosantoniodasilva commented on an outdated diff Apr 24, 2012

activerecord/lib/active_record/base.rb
@attributes = cloned_attributes
+ @errors = cloned_errors
@carlosantoniodasilva

carlosantoniodasilva Apr 24, 2012

Owner

It's possible to just set @errors = nil, and avoid the variable.

Member

josevalim commented Apr 24, 2012

👍 for moving to active model and cloning the errors object as well

Owner

acapilleri commented on 6486369 May 12, 2012

any news?

acapilleri closed this May 12, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment