db.commit --> db.session.commit + oter bugfixes