django执行mysql恢复的时候出现“The request's session was deleted before the request completed. The user may have logged out in a concurrent request, for example.”

版本:

django:2.1.7

python:3.7

mysql:5.7.25

 

今天在用django做mysql备份和恢复的时候,备份没问题,恢复时出现如下错误提示:

The request's session was deleted before the request completed. The user may have logged out in a concurrent request, for example.

恢复的命令如下:

recoverycmd = "mysql -u" +DB_USER + " -p"+DB_USER_PASSWD+" " +DB_NAME+" < "+sql_file
os.system(recoverycmd)

因为我是在二级页面中选择备份的脚本文件,一开始以为os.system是异步执行的,导致二级页面结束跳转到一级页面了,一想又不对,那也顶多提前跳出完成提示,不会打断恢复啊。

所有肯定是被什么打断了,然后测试了一下,发现每次错误时,登录都会退出。原来,函数前加了下面的语句:

@login_required(login_url='/login')

导致了恢复过程中,数据库连接已经断开,验证用户登录,导致验证失败,恢复过程被中断出现异常。

 

结论:于是,把这个语句删除,mysql恢复顺利进行,但是数据库连接还是会断开一次,重新登录下就好了。

 

你可能感兴趣的:(django执行mysql恢复的时候出现“The request's session was deleted before the request completed. The user may have logged out in a concurrent request, for example.”)