我有以下代码片段可以对表Customer进行操作:
with session.begin(subtransactions=True):
db_obj = Customer(...)
result = io_processing() # may cause greenlet switching
# I do not want to make it inside the transaction above,
# Because some legacy I/O related code which will causes greenlet switching
if result:
self.read_write_db(session, db_obj)
在读写功能中:
^{pr2}$将事务外部的“db_obj”传递到另一个函数是否安全?在
或者我必须在读写数据库中再次查询db_obj并更新它?在
是的,这是可能的,但是您必须通过在
read_write_db
的会话中合并db_obj
来获得一个新实例。在有关所有详细信息,请参见http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#merging。合并可能很棘手。在
相关问题 更多 >
编程相关推荐