Replies: 2 comments 4 replies
-
You need to have a separate savepoint around each call that can fail: def crt(code)
puts "ATTEMPTING TO INSERT #{code}"
begin
DB.transaction(rollback: :always, auto_savepoint: true, savepoint: true) do
DB[:models].insert(code: code)
end
rescue Sequel::UniqueConstraintViolation
puts "Duplicate code: #{code}"
end
end
crt("a")
crt("a")
crt("a") |
Beta Was this translation helpful? Give feedback.
4 replies
-
Oh yes, now I understand. The following explanation also helped me:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey 👋,
please checkout following example. The outer transaction has
auto_savepoint: true
. I think that noPG::InFailedSqlTransaction
should take place because of this. But it happens, but only on the 2nd failing attempt.To explain how I came across this problem:
I have this problem in a test suite. Records with unique codes are to be inserted in the code to be tested. If a generated code already exists, another attempt should be started.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions