admin管理员组文章数量:1333746
tornado做一个商城,进入联系卖家聊天窗时抛出异常"(raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely)"
解决办法:使用 with session.no_autoflush:
示例:
抛异常代码:
me = session.query(User).filter_by(id=int(my_id)).first()
he = session.query(User).filter_by(id=int(his_id)).first()
# 获取聊天记录
records=session.query(ChatRecord).filter(or_(and_(ChatRecord.who_send==int(my_id),ChatRecord.who_recv==int(his_id)),and_(ChatRecord.who_send==int(his_id),ChatRecord.who_recv==int(my_id)))).order_by('id').all()
将数据库操作的代码用with session.no_autoflush:包裹,不自动刷新:
with session.no_autoflush:
me = session.query(User).filter_by(id=int(my_id)).first()
he = session.query(User).filter_by(id=int(his_id)).first()
# 获取聊天记录
records = session.query(ChatRecord).filter(or_(and_(ChatRecord.who_send==int(my_id),ChatRecord.who_recv==int(his_id)),and_(ChatRecord.who_send==int(his_id),ChatRecord.who_recv==int(my_id)))).order_by('id').all()
欢迎关注wx公众号:python web小栈,共同探讨学习
本文标签: Queryinvokedraisedresultnoautoflush
版权声明:本文标题:raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1738336753a2077062.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论