
raised as a result of Query
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()
👁️ 阅读量:0
© 版权声明:本文《raised as a result of Query》内容均为本站精心整理或网友自愿分享,如需转载请注明原文出处:https://www.zastudy.cn/wen/1686554529a290539.html。