Dont call __setitem__ while holding db connection open

This commit is contained in:
Kovid Goyal 2020-09-01 09:26:19 +05:30
parent 4d992eaa69
commit 13259a4c9c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -120,6 +120,7 @@ class DBPrefs(dict): # {{{
def __setitem__(self, key, val):
if not self.disable_setting:
raw = self.to_raw(val)
do_set = False
with self.db.conn:
try:
dbraw = next(self.db.execute('SELECT id,val FROM preferences WHERE key=?', (key,)))
@ -130,7 +131,9 @@ class DBPrefs(dict): # {{{
self.db.execute('INSERT INTO preferences (key,val) VALUES (?,?)', (key, raw))
else:
self.db.execute('UPDATE preferences SET val=? WHERE id=?', (raw, dbraw[0]))
dict.__setitem__(self, key, val)
do_set = True
if do_set:
dict.__setitem__(self, key, val)
def set(self, key, val):
self.__setitem__(key, val)