AR optimistic locking error when not using #attributes=?


#1

Hello all,
Please review this script/console output (using Login Generator
modified) :

users = User.find(:all, :limit=>10)
=> […]

users.each do |user|
?> user.password = user.password_orig

user.password_confirmation = user.password_orig
user.save
end
ActiveRecord::StaleObjectError: Attempted to update a stale object
from
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/locking.rb:42:in
update_without_callb acks' from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/callbacks.rb:274:inupdate_without_ti
mestamps’
from
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/timestamp.rb:39:in
update' from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1431:increate_or_update_with
out_callbacks’
from
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/callbacks.rb:249:in
`create_or_update’

from
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base.rb:1231:in
save_without_validati on' from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/validations.rb:687:insave_without_tr
ansactions’
from
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:in
save' from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:intransaction’
from
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:91:in
transaction' from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:118:intransaction’
from
C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/transactions.rb:126:in
save' from (irb):5 from (irb):3:ineach’
from (irb):3

users.each do |user|
?> user.attributes = {:password=>user.password_orig,
:password_confirmation=>user.password_orig}

user.save
end
=> […] #success
Why is AR buying day-old bread when the object is updated on separate
lines ?
Is this a bug I should be reporting ?