下面的说明似乎不起作用。我试图提交一个表的更新,然后立即读取该值,但该表似乎没有及时更新。。。但它正在提交,因为在此之后,我检查了表,值从20更改为25。为什么flask SQL Alchemy的作用域为_session.commit()没有及时更新数据库/我应该如何在之后立即读取更新的值
def myFunc(db):
scoped_session = db.create_scoped_session()
before = get_detail(1)
print(before.amount) # is 20 right now
data = {"id":1, "amount":25}
save = update_detail(data, scoped_session)
after = test_get_invest_detail(1)
print(after.amount) # want it to be 25 but get 20 bc I believe db isn't updated in time
def update_detail(data, scoped_session):
row = scoped_session.query(MyTable).filter(MyTable.id == data['id'])
if row:
row.update(data, synchronize_session=False)
return 1
else:
return 0
def get_detail(id):
return MyTable.query.filter_by(id=id).first()
目前没有回答
相关问题 更多 >
编程相关推荐