Skip to content

Commit

Permalink
Release connection correctly when no open transactions (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmcgarvey authored Jan 25, 2022
1 parent ac281f4 commit 519213e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions spec/avram/transaction_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ describe "Avram::SaveOperation" do
operation.saved?.should be_true
end
end

it "releases connection after operation finishes and no transactions open", tags: Avram::SpecHelper::TRUNCATE do
PostTransactionSaveOperation.create!(title: "New Title", rollback_after_save: false)
TestDatabase.connections.should be_empty
end
end

describe "raising an error" do
Expand Down
3 changes: 1 addition & 2 deletions src/avram/database.cr
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ abstract class Avram::Database
rescue e : Avram::Rollback
false
ensure
# TODO: not sure of this
if current_connection._avram_in_transaction?
if !current_connection._avram_in_transaction?
current_connection.release
connections.delete(object_id)
end
Expand Down

0 comments on commit 519213e

Please sign in to comment.