error traceback while closing the mailbox
vu3rdd opened this issue · 0 comments
vu3rdd commented
I am trying to implement a solution for a scenario where the sender creates a mailbox, gets the code but before they even send the code to the recipient, changes the mind and decides to cancel the connection. Normally, the mailbox would get pruned in the process. If I send a close message (say in a handler for SIGINT
), I get these errors:
[...]
File "/home/ram/work/magic-wormhole-mailbox-server/src/wormhole_mailbox_server/server_websocket.py", line 160, in onMessage
return self.handle_close(msg, server_rx)
File "/home/ram/work/magic-wormhole-mailbox-server/src/wormhole_mailbox_server/server_websocket.py", line 293, in handle_close
self._mailbox.close(self._side, msg.get("mood"), server_rx)
File "/home/ram/work/magic-wormhole-mailbox-server/src/wormhole_mailbox_server/server.py", line 151, in close
db.execute("DELETE FROM `mailboxes` WHERE `id`=?", (self._mailbox_id,))
sqlite3.IntegrityError: FOREIGN KEY constraint failed
I guess this arises because there are other tables that depend on the mailbox_id
key in the mailboxes
table. So, deleting them first before deleting mailboxes, seem to fix the problem:
diff --git a/src/wormhole_mailbox_server/server.py b/src/wormhole_mailbox_server/server.py
index 0f74145..4eba791 100644
--- a/src/wormhole_mailbox_server/server.py
+++ b/src/wormhole_mailbox_server/server.py
@@ -142,6 +142,10 @@ class Mailbox:
return
# nope. delete and summarize
+ db.execute("DELETE FROM `nameplate_sides` WHERE `side`=?",
+ (side,))
+ db.execute("DELETE FROM `nameplates` WHERE `mailbox_id`=?",
+ (self._mailbox_id,))
db.execute("DELETE FROM `messages` WHERE `mailbox_id`=?",
(self._mailbox_id,))
db.execute("DELETE FROM `mailbox_sides` WHERE `mailbox_id`=?",