From 3bea711f15331d4e8d1455f8c4b02ed53e7568d0 Mon Sep 17 00:00:00 2001 From: Jeremy Liu Date: Thu, 26 Oct 2017 17:43:44 +0800 Subject: [PATCH] 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 --- barbican/model/repositories.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/barbican/model/repositories.py b/barbican/model/repositories.py index 1074a0db6..b9b490441 100644 --- a/barbican/model/repositories.py +++ b/barbican/model/repositories.py @@ -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)