Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Commit

Permalink
This change causes unexpected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
sato11 committed Apr 25, 2022
1 parent 169a98a commit 5f8d90b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/models/post.rb
Expand Up @@ -3,9 +3,11 @@ class Post < ApplicationRecord

def add_comment
retries = 0
ApplicationRecord.transaction do
comment = Comment.new(post_id: id)
comment.save!
begin
ApplicationRecord.transaction do
comment = Comment.new(post_id: id)
comment.save!
end
rescue ActiveRecord::Deadlocked => e
if retries < 1
retries += 1
Expand Down

0 comments on commit 5f8d90b

Please sign in to comment.