助けが必要です。数日前、私は自分の Web プロジェクトをサーバーにデプロイしました。すべてうまくいきました。 Msyql の "wait_timeout=2880000" および "interactive_timeout = 2880000" の conf が原因であることがわかりました。また、"set pool_recycle=7200 when create_engine" などの解決策も得られましたが、機能しません。ある人は、「if を使用した後に session.close() を実行する必要がある」と言っています。試してみようとしましたが、別のエラーが発生しました。sqlalchemy.orm.relation を使用しました。クラス User と Role.今、私は DBSession.close() のように追加します
@classmethod
def get_by_id(cls, id):
user_ = DBSession.query(cls).get(id)
DBSession.close()
return user_
しかし、今私がこれをしたとき
user = User.get_by_id(1)
user.roles
ERROR:Parent instance <User at 0xace51cc> is not bound to a Session;
lazy load operation of attribute 'roles' cannot proceed
どうすれば私の問題を解決できますか。