Fix Name editor crash after clearing a group_as name on dbapi dbs (#771)

Fixes #10981
This commit is contained in:
Paul Culley 2019-01-21 21:19:25 -06:00 committed by Sam Manzi
parent dba752c328
commit abcf304ea7

View File

@ -576,14 +576,18 @@ class DBAPI(DbGeneric):
self.dbapi.execute("SELECT 1 FROM name_group WHERE name = ?", self.dbapi.execute("SELECT 1 FROM name_group WHERE name = ?",
[name]) [name])
row = self.dbapi.fetchone() row = self.dbapi.fetchone()
if row: if row and grouping is not None:
self.dbapi.execute("UPDATE name_group SET grouping=? " self.dbapi.execute("UPDATE name_group SET grouping=? "
"WHERE name = ?", [grouping, name]) "WHERE name = ?", [grouping, name])
elif row and grouping is None:
self.dbapi.execute("DELETE FROM name_group WHERE name = ?", [name])
grouping = ''
else: else:
self.dbapi.execute( self.dbapi.execute(
"INSERT INTO name_group (name, grouping) VALUES (?, ?)", "INSERT INTO name_group (name, grouping) VALUES (?, ?)",
[name, grouping]) [name, grouping])
self._txn_commit() self._txn_commit()
self.emit('person-groupname-rebuild', (name, grouping))
def _commit_base(self, obj, obj_key, trans, change_time): def _commit_base(self, obj, obj_key, trans, change_time):
""" """