Skip to content

Commit 3666d2c

Browse files
authored
Merge pull request CloudBotIRC#188 from linuxdaemon/gonzobot+handle-autojoin-db-errors
Handle integrity errors in autojoin.py
2 parents aa6f970 + 21c1eb2 commit 3666d2c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

plugins/autojoin.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from threading import RLock
44

55
from sqlalchemy import PrimaryKeyConstraint, Column, String, Table, and_
6+
from sqlalchemy.exc import IntegrityError
67

78
from cloudbot import hook
89
from cloudbot.util import database
@@ -46,10 +47,14 @@ def add_chan(db, conn, chan, nick):
4647
chan = chan.casefold()
4748
if nick.casefold() == conn.nick.casefold() and chan not in chans:
4849
with db_lock:
49-
db.execute(table.insert().values(conn=conn.name.casefold(), chan=chan.casefold()))
50-
db.commit()
51-
52-
load_cache(db)
50+
try:
51+
db.execute(table.insert().values(conn=conn.name.casefold(), chan=chan.casefold()))
52+
except IntegrityError:
53+
db.rollback()
54+
else:
55+
db.commit()
56+
57+
load_cache(db)
5358

5459

5560
@hook.irc_raw('PART', singlethread=True)

0 commit comments

Comments
 (0)