Skip to content

Commit 519213e

Browse files
authoredJan 25, 2022
Release connection correctly when no open transactions (#800)
1 parent ac281f4 commit 519213e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎spec/avram/transaction_spec.cr

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ describe "Avram::SaveOperation" do
6666
operation.saved?.should be_true
6767
end
6868
end
69+
70+
it "releases connection after operation finishes and no transactions open", tags: Avram::SpecHelper::TRUNCATE do
71+
PostTransactionSaveOperation.create!(title: "New Title", rollback_after_save: false)
72+
TestDatabase.connections.should be_empty
73+
end
6974
end
7075

7176
describe "raising an error" do

‎src/avram/database.cr

+1-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ abstract class Avram::Database
221221
rescue e : Avram::Rollback
222222
false
223223
ensure
224-
# TODO: not sure of this
225-
if current_connection._avram_in_transaction?
224+
if !current_connection._avram_in_transaction?
226225
current_connection.release
227226
connections.delete(object_id)
228227
end

0 commit comments

Comments
 (0)
Please sign in to comment.