summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-09-26 18:32:09 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-09-26 18:32:09 -0400
commit87f0f69ec1daa118bb459c0729ba3905abc28523 (patch)
tree443aefd315286eda813c89771d87ba793f8e4619
parent10f54a354d4668fdee2d51750d9064cc2e8b6a88 (diff)
downloadpypaste-87f0f69ec1daa118bb459c0729ba3905abc28523.tar.gz
make sure to try/catch around database transactions
-rw-r--r--pypaste/server/sqlite/__init__.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/pypaste/server/sqlite/__init__.py b/pypaste/server/sqlite/__init__.py
index 7e490aa..be07db6 100644
--- a/pypaste/server/sqlite/__init__.py
+++ b/pypaste/server/sqlite/__init__.py
@@ -23,20 +23,24 @@ class Sqlite(Storage):
data = await asyncio.to_thread(compress)
- await self.connection.execute(
- "insert into pastes values(?, ?, ?, ?, ?)",
- (key.data, key.length, paste.dt.isoformat(), len(data), paste.syntax),
- )
-
- await self.connection.execute(
- "insert into sqlite values(?, ?)",
- (
- key.data,
- data,
- ),
- )
+ try:
+ await self.connection.execute(
+ "insert into pastes values(?, ?, ?, ?, ?)",
+ (key.data, key.length, paste.dt.isoformat(), len(data), paste.syntax),
+ )
+
+ await self.connection.execute(
+ "insert into sqlite values(?, ?)",
+ (
+ key.data,
+ data,
+ ),
+ )
- await self.connection.commit()
+ await self.connection.commit()
+ except Exception as e:
+ await self.connection.rollback()
+ raise e
async def retrieve(self, key: Key) -> Optional[Paste]:
async with self.connection.execute(
@@ -62,9 +66,16 @@ class Sqlite(Storage):
return Paste(info.dt, info.syntax, text)
async def delete(self, key: Key) -> None:
- await self.connection.execute("delete from pastes where key=?", (key.data,))
+ try:
+ await self.connection.execute("delete from pastes where key=?", (key.data,))
+
+ await self.connection.execute("delete from sqlite where key=?", (key.data,))
+
+ await self.connection.commit()
+ except Exception as e:
+ await self.connection.rollback()
- await self.connection.execute("delete from sqlite where key=?", (key.data,))
+ raise e
async def exists(self, key: Key) -> bool:
async with self.connection.execute(