diff --git a/app/scodoc/notesdb.py b/app/scodoc/notesdb.py index 4342d128bc..796f6edf20 100644 --- a/app/scodoc/notesdb.py +++ b/app/scodoc/notesdb.py @@ -82,7 +82,7 @@ def SimpleDictFetch(query, args, cursor=None): return cursor.dictfetchall() -def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1): +def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1, return_id=True): """insert into table values in dict 'vals' Return: id de l'object créé """ @@ -104,8 +104,11 @@ def DBInsertDict(cnx, table, vals, commit=0, convert_empty_to_nulls=1): ) else: cursor.execute("insert into %s default values" % table) - cursor.execute(f"SELECT CURRVAL('{table}_id_seq')") # id créé - oid = cursor.fetchone()[0] + if return_id: + cursor.execute(f"SELECT CURRVAL('{table}_id_seq')") # id créé + oid = cursor.fetchone()[0] + else: + oid = None except: log("DBInsertDict: EXCEPTION !") log("DBInsertDict: table=%s, vals=%s" % (str(table), str(vals))) @@ -305,7 +308,13 @@ class EditableTable(object): if title in self.input_formators: vals[title] = self.input_formators[title](vals[title]) # insert - new_id = DBInsertDict(cnx, self.table_name, vals, commit=True) + new_id = DBInsertDict( + cnx, + self.table_name, + vals, + commit=True, + return_id=(self.id_name is not None), + ) return new_id def delete(self, cnx, oid, commit=True):