Created
January 19, 2012 02:23
-
-
Save rorcraft/1637279 to your computer and use it in GitHub Desktop.
ActiveRecord changes attributes in a rolled back transaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
after_create :deadlock_on_first_try | |
def deadlock_on_first_try | |
raise ActiveRecord::StatementInvalid.new("Lock wait timeout exceeded") if @deadlocked.nil? | |
ensure | |
@deadlocked = true | |
end | |
end | |
# In the console... | |
>@user = User.new | |
>@user.name = "foo" | |
>User.transaction do @user.save end | |
ActiveRecord::StatementInvalid: Lock wait timeout exceeded | |
>@user.new_record? | |
false | |
>@user.id | |
1 | |
>User.find(1) | |
ActiveRecord::RecordNotFound: Couldn't find User with id=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment