from .. import db from ..decorators import background from ..models import User @background def delete_user(user_id, *args, **kwargs): with kwargs['app'].app_context(): user = User.query.get(user_id) if user is None: raise Exception(f'User {user_id} not found') user.delete() db.session.commit()