Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close SQLite pool even when there is error #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/mayim/sql/sqlite/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ async def connection(self, timeout: Optional[float] = None):
existing = self.existing_connection()
close_when_done = False

if existing:
yield existing
else:
if not self._db:
close_when_done = True
await self.open()
yield self._db

transaction = self.in_transaction()
commit = self.do_commit()

if not transaction:
if commit:
await self._db.commit() # type: ignore

if close_when_done:
await self.close()
try:
if existing:
yield existing
else:
if not self._db:
close_when_done = True
await self.open()
yield self._db

transaction = self.in_transaction()
commit = self.do_commit()

if not transaction:
if commit:
await self._db.commit() # type: ignore
finally:
if close_when_done:
await self.close()