try:
user = await User.create(
username=username,
password=password,
update_time=time_now()
)
await UserInfo.create(
user_id=user.id,
name=name, phone=phone,
age=age, gender=gender,
email=email, birthday=birthday,
update_time=time_now()
)
msg = "User:{} registered success !".format(username)
logger.info(msg)
except DatabaseError as e:
msg = "Database error:{}".format(e, e.__traceback__.tb_lineno)
logger.error(msg)
return make_error_response(code=RespCode.database_error, message=msg)
except Exception as e:
msg = "Add user: {} info failed:{}, line: {}".format(username, e, e.__traceback__.tb_lineno)
logger.error(msg)
# rollback()
return make_error_response(code=RespCode.user_register_failed, message=msg)
像这段代码,用户创建成功,但是在创建用户信息时,一个字段太长导致创建失败,用户没有回滚。对了,我没发现龟龟有回滚的功能,没必要吧?