Peter Fitzgibbons
2005-Nov-15 17:23 UTC
AR optimistic locking error when not using #attributes= ?
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 >> endActiveRecord::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:in `update_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:in `create_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:in `save_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:in `transaction'' 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:in `transaction'' 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:in `each'' 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 ? -- Peter Fitzgibbons _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails