summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-11-20 21:06:40 +0000
committerGerrit Code Review <review@openstack.org>2016-11-20 21:06:40 +0000
commitde9f89b60c719698f4be36abe4cef299b96671b4 (patch)
tree4aaee78732564a2097508a7b2f6dd5bb3a6e6d9c
parenta82cd38189f09da8773c1186b661fc71f529b7ae (diff)
parent8e96b95eb58fc02c13c378c6ea7ca96ae51a9164 (diff)
downloadoslo-db-de9f89b60c719698f4be36abe4cef299b96671b4.tar.gz
Merge "Adjust SAVEPOINT cause test for SQLA 1.1"
-rw-r--r--oslo_db/sqlalchemy/compat/utils.py1
-rw-r--r--oslo_db/tests/sqlalchemy/test_exc_filters.py41
2 files changed, 29 insertions, 13 deletions
diff --git a/oslo_db/sqlalchemy/compat/utils.py b/oslo_db/sqlalchemy/compat/utils.py
index 8ebffcc..e34e70f 100644
--- a/oslo_db/sqlalchemy/compat/utils.py
+++ b/oslo_db/sqlalchemy/compat/utils.py
@@ -19,6 +19,7 @@ SQLA_VERSION = tuple(
for num in sqlalchemy.__version__.split(".")
)
+sqla_110 = SQLA_VERSION >= (1, 1, 0)
sqla_100 = SQLA_VERSION >= (1, 0, 0)
sqla_097 = SQLA_VERSION >= (0, 9, 7)
sqla_094 = SQLA_VERSION >= (0, 9, 4)
diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py
index a45214d..8e62a77 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -28,6 +28,7 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import mapper
from oslo_db import exception
+from oslo_db.sqlalchemy.compat import utils as compat_utils
from oslo_db.sqlalchemy import engines
from oslo_db.sqlalchemy import exc_filters
from oslo_db.tests.sqlalchemy import base as test_base
@@ -666,22 +667,36 @@ class TestExceptionCauseMySQLSavepoint(test_base.MySQLOpportunisticTestCase):
# from the "with session.begin_nested()"
except exception.DBError as dbe_inner:
- # first "cause" is the failed SAVEPOINT rollback
- # from inside of flush(), when it fails
- self.assertTrue(
- isinstance(
- dbe_inner.cause,
- exception.DBError
+ if not compat_utils.sqla_110:
+ # first "cause" is the failed SAVEPOINT rollback
+ # from inside of flush(), when it fails
+ self.assertTrue(
+ isinstance(
+ dbe_inner.cause,
+ exception.DBError
+ )
)
- )
- # second "cause" is then the actual DB duplicate
- self.assertTrue(
- isinstance(
- dbe_inner.cause.cause,
- exception.DBDuplicateEntry
+ # second "cause" is then the actual DB duplicate
+ self.assertTrue(
+ isinstance(
+ dbe_inner.cause.cause,
+ exception.DBDuplicateEntry
+ )
)
- )
+ else:
+ # in SQLA 1.1, the rollback() method of Session
+ # catches the error and repairs the state of the
+ # session even though the SAVEPOINT was lost;
+ # the net result here is that one exception is thrown
+ # instead of two. This is SQLAlchemy ticket #3680
+ self.assertTrue(
+ isinstance(
+ dbe_inner.cause,
+ exception.DBDuplicateEntry
+ )
+ )
+
except exception.DBError as dbe_outer:
self.assertTrue(
isinstance(