1
即時獲得此AttributeError: __enter__
當我嘗試使用像這樣guide sqlalchemy會話。AttributeError:__enter__使用聲明SqlAlchemy會話
我的代碼:
Session = scoped_session(sessionmaker(autoflush=True, autocommit=False, bind=engine))
@contextmanager
def session_scope():
session = Session()
try:
yield session
session.commit()
except:
session.rollback()
raise
finally:
session.close()
class SomeClass:
def __init__(self):
self.session_scope = session_scope
def something_with_session(self):
with self.session_scope as session: <-- error
我在做什麼錯?我使用python 3.6
您可以發佈完整的追溯,以顯示問題的所在範圍內? – tdelaney