Improve autonested_transaction
Currently in method autonested_transaction from db.api is decided begin(nested) or begin(subtransactions) should be used based on catching the the exception. Instead of this it can be checking is there active session or not. Change-Id: I2b5951bcffef99323e3d68034ae9a3fd9fa1970c
This commit is contained in:
parent
d56b5a6718
commit
e072d06ce6
|
@ -21,7 +21,6 @@ from oslo_db import exception as db_exc
|
|||
from oslo_db.sqlalchemy import session
|
||||
from oslo_utils import excutils
|
||||
from oslo_utils import uuidutils
|
||||
from sqlalchemy import exc
|
||||
|
||||
from neutron.common import exceptions as n_exc
|
||||
from neutron.db import common_db_mixin
|
||||
|
@ -81,13 +80,12 @@ def get_session(autocommit=True, expire_on_commit=False, use_slave=False):
|
|||
@contextlib.contextmanager
|
||||
def autonested_transaction(sess):
|
||||
"""This is a convenience method to not bother with 'nested' parameter."""
|
||||
try:
|
||||
session_context = sess.begin_nested()
|
||||
except exc.InvalidRequestError:
|
||||
if sess.is_active:
|
||||
session_context = sess.begin(nested=True)
|
||||
else:
|
||||
session_context = sess.begin(subtransactions=True)
|
||||
finally:
|
||||
with session_context as tx:
|
||||
yield tx
|
||||
with session_context as tx:
|
||||
yield tx
|
||||
|
||||
|
||||
# Common database operation implementations
|
||||
|
|
Loading…
Reference in New Issue