diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index baae1e96a5..abe07a12a1 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -106,10 +106,15 @@ class DBPrefs(dict): # {{{ self.db.execute('DELETE FROM preferences WHERE key=?', (key,)) def __setitem__(self, key, val): - if not self.disable_setting and val != self[key]: - raw = self.to_raw(val) - self.db.execute('INSERT OR REPLACE INTO preferences (key,val) VALUES (?,?)', (key, raw)) - dict.__setitem__(self, key, val) + if not self.disable_setting: + try: + current_val = self[key] + except KeyError: + current_val = object() + if val != current_val: + raw = self.to_raw(val) + self.db.execute('INSERT OR REPLACE INTO preferences (key,val) VALUES (?,?)', (key, raw)) + dict.__setitem__(self, key, val) def set(self, key, val): self.__setitem__(key, val)