def update(noteid, note_name): update_note = Note.query.filter(Note.noteid == noteid).one_or_none() existing_note = Note.query.filter( Note.note_name == note_name).one_or_none() if update_note is None: abort(404, "Note not found for ID {}.".format(noteid)) elif existing_note is not None: abort(409, "Note {} already exists.".format(note_name)) else: update = Note(note_name) update.noteid = noteid db.session.merge(update) db.session.commit() schema = NoteSchema() data = schema.dump(update) return data, 200