Rails: ActiveRecord::StaleObjectError: Attempted to update a stale object: Order
Two users/processes updated the same record; the second save failed the lock_version check.
ActiveRecord::StaleObjectError: Attempted to update a stale object: OrderAttempted to update a stale object: UserActiveRecord::StaleObjectError (Attempted to update a stale object)optimistic locking stale object Rails Meaning
This is optimistic locking working as designed (a lock_version column exists). Reload the record and reapply the change, or show a conflict message to the user. Remove the lock_version column if you don't want it, or retry in background jobs with record.reload.
Common causes
- Concurrent edits to the same row
lock_versioncolumn present- Long-lived form edit and another update
- Jobs updating the same record
- Stale object kept in memory
⚡ Quick fix
rescue ActiveRecord::StaleObjectErrorthen reload and retry or notify the user- Use atomic updates (
update_all,increment!) for counters - Remove
lock_versionif not needed
Detailed fix by platform
Rails
begin; order.update!(attrs); rescue ActiveRecord::StaleObjectError; order.reload; retry; end
How to diagnose
- Concurrency — Two writers?
- Column — lock_version?
- Handling — Reload/retry?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- 1213 MySQL ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
- ActiveRecord::AssociationTypeMismatch Rails: ActiveRecord::AssociationTypeMismatch: User(#1234) expected, got "42" which is an instance of String(#5678)
- ActiveRecord::ConnectionNotEstablished Rails: ActiveRecord::ConnectionNotEstablished: No connection pool for 'ActiveRecord::Base' found
Most viewed in Ruby / Rails
- ActiveRecord::PendingMigrationError Rails: ActiveRecord::PendingMigrationError — Migrations are pending. To resolve this issue, run: bin/rails db:migrate
- undefined method for nil Ruby: NoMethodError: undefined method `x' for nil (nil:NilClass)
- ActionController::InvalidAuthenticityToken Rails: ActionController::InvalidAuthenticityToken (Can't verify CSRF token authenticity)
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026