我有一个包含设备信息的表(有一个id属性是主键,由DB自动分配),我运行以下代码:
session.autoflush = False
try:
devices = model.Device.get_all_by_name(session, dev_data.index.tolist())
for idx, device in enumerate(devices):
device.update(dev_data.ix[device.name])
if 0 == idx % 500 and idx != 0:
session.flush()
except Exception as exp:
# exception handling here
else:
session.commit()
session.expunge_all()
# calling the next line throws 'Instance not bound to a session' error
logger.debug('Device info after expunge: {}'.format(devices[-1].name))
finally:
session.close()
每当我尝试访问其中一个设备的属性时,会抛出一个exeption,但是我想expunge_all()应该分离对象,并且在提交或刷新时,所有python对象都应该是snychronized,对吗?