Forum: Ruby on Rails AR optimistic locking error when not using #attributes= ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
peter.fitzgibbons (Guest)
on 2005-11-15 19:24
(Received via mailing list)
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: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 ?
This topic is locked and can not be replied to.