Database session need to rollback after duplication

When a session is first used for accessing database but fails, it
need to rollback before being used again.

Change-Id: I82065e4add3a9a5d0906734bb124617658491c31
Closes-bug: #1727667
This commit is contained in:
Jeremy Liu 2017-10-26 17:43:44 +08:00
parent 13d1c137f4
commit 3bea711f15

View File

@ -393,6 +393,7 @@ class BaseRepo(object):
raise exception.Invalid(msg)
LOG.debug("Begin create from...")
session = self.get_session(session)
start = time.time() # DEBUG
# Validate the attributes before we go any further. From my
@ -406,6 +407,7 @@ class BaseRepo(object):
LOG.debug("Saving entity...")
entity.save(session=session)
except db_exc.DBDuplicateEntry as e:
session.rollback()
LOG.exception('Problem saving entity for create')
error_msg = re.sub('[()]', '', str(e.args))
raise exception.ConstraintCheck(error=error_msg)