python - Sqlalchemy 似乎在不应该的时候提交了更改

标签 python postgresql sqlalchemy

考虑以下 Python 代码片段:

from sqlalchemy import *
from sqlalchemy.orm import *
db = create_engine('postgresql:///database', isolation_level='SERIALIZABLE')
Session = scoped_session(sessionmaker(bind=db, autocommit=False))
s = Session()
s.add(SomeInstance())
s.flush()
raw_input('Did it work? ')

它连接到数据库,将 SomeInstance 添加到 session 中,刷新,然后暂停。此时,如果我 psql 进入我的数据库,我会看到该实例已经被插入——即使自动提交是 False 并且我还没有提交 session !

知道我可能做错了什么吗?

谢谢!

最佳答案

没关系,sqlalchemy 0.6.3 中的 psycopg2.py 实现有一个错误;升级到 0.6.4 解决了这个问题。

关于python - Sqlalchemy 似乎在不应该的时候提交了更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3664624/

相关文章:

python - numpy 中的多维 bool 数组索引

Python:带有日期时间轴的 HoverToolol

Python KeyError : <peewee. IntegerField 对象在 ... > 使用 peewee insert_many()

ruby-on-rails - 如果项目存在 x 次则运行代码

sql - 按星期几分组

python - 随机 Numpy 数组的逐元素种子

python - Tkinter 密码系统

python - 当相关列不存在时 SQLAlchemy 忽略过滤器

python - 在 Pandas to_sql 中指定模式

python - SQLAlchemy 中的 with_entities 和 load_only 有什么区别?