Skip to content

Commit 4940755

Browse files
committed
Drop table in finally
Refs #653 (comment)
1 parent 41497c3 commit 4940755

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sqlite_utils/db.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ def supports_strict(self) -> bool:
692692
def supports_on_conflict(self) -> bool:
693693
# SQLite's upsert is implemented as INSERT INTO ... ON CONFLICT DO ...
694694
if not hasattr(self, "_supports_on_conflict"):
695+
table_name = "t{}".format(secrets.token_hex(16))
695696
try:
696-
table_name = "t{}".format(secrets.token_hex(16))
697697
with self.conn:
698698
self.conn.execute(
699699
"create table {} (id integer primary key, name text)".format(
@@ -709,10 +709,11 @@ def supports_on_conflict(self) -> bool:
709709
"on conflict do update set name = 'two'"
710710
).format(table_name)
711711
)
712-
self.conn.execute("drop table {}".format(table_name))
713-
self._supports_on_conflict = True
712+
self._supports_on_conflict = True
714713
except Exception:
715714
self._supports_on_conflict = False
715+
finally:
716+
self.conn.execute("drop table {}".format(table_name))
716717
return self._supports_on_conflict
717718

718719
@property

0 commit comments

Comments
 (0)