def create_user(data: dict): user = User() user.login = data.get("login") user.password = data.get("password") try: with db.atomic() as transaction: try: user.save() except peewee.InternalError: transaction.rollback() else: transaction.commit() except peewee.IntegrityError: print(f"{data.get('login')}: Already exist.") return user.id
def create_user(data): user = User() user.login = data.get("login") user.password = data.get("password") try: # атомик - если все транзакции успешные, # тогда сохр, а если нет, то ничего не сохр with db.atomic() as transaction: try: user.save() except peewee.InternalError as e: transaction.rollback() print(e) print("ERROR") else: transaction.commit() print("COMMIT") except peewee.IntegrityError: print(f"{data.get('login')}: Already exist.") return user.id