Skip to content

Commit c9f4171

Browse files
committed
commit transaction after calling super().drop_schema() so that DETACH doesn't raise 'database is locked' error
1 parent f4f0f04 commit c9f4171

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dbt/adapters/sqlite/impl.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ def timestamp_add_sql(
244244
def drop_schema(self, relation: BaseRelation) -> None:
245245
super().drop_schema(relation)
246246

247+
# can't detach a databse in the middle of a transaction, so commit first.
248+
# I wonder if drop_schema() in SQLAdapter should do this, since create_schema() does.
249+
self.commit_if_has_connection()
250+
247251
# never detach main
248252
if relation.schema != 'main':
249-
self.connections.execute(f"DETACH DATABASE {relation.schema}")
253+
if self.check_schema_exists(relation.database, relation.schema):
254+
self.connections.execute(f"DETACH DATABASE {relation.schema}")

0 commit comments

Comments
 (0)