2014-03-05 09:10:09 |
ChangBo Guo(gcb) |
description |
Current code use ModelBase.save() always submit a commit even inside a block fo with session.begin().
this is not purpose of using session.begin() to organize some operations in one transaction
1)session.begin() will return a SessionTransaction instance, then call SessionTransaction.__enter__()
and do something in with block, then call SessionTransaction.__exit__(), in method __exit__() will commit or rollback automatically. See https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/orm/session.py#L451
2) There is also suggestion metioned in https://github.com/openstack/nova/blob/master/nova/openstack/common/db/sqlalchemy/session.py#L76
3) ModelBase.save() begin another transaction see https://github.com/openstack/nova/blob/master/nova/openstack/common/db/sqlalchemy/models.py#L51
so we'd better don't use ModelBase.save() inside of block session.begin() |
Current code use ModelBase.save() always submit a commit even inside a block fo with session.begin().
this is not purpose of using session.begin() to organize some operations in one transaction
1)session.begin() will return a SessionTransaction instance, then call SessionTransaction.__enter__()
and do something in with block, then call SessionTransaction.__exit__(), in method __exit__() will commit or rollback automatically. See https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/orm/session.py#L454
2) There is also suggestion metioned in https://github.com/openstack/oslo-incubator/blob/master/openstack/common/db/sqlalchemy/session.py#L71
3) ModelBase.save() begin another transaction see https://github.com/openstack/oslo-incubator/blob/master/openstack/common/db/sqlalchemy/models.py#L47
so we'd better don't use ModelBase.save() inside of block session.begin() |
|