summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2016-11-15 17:31:05 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2016-11-16 12:41:40 -0500
commit8e96b95eb58fc02c13c378c6ea7ca96ae51a9164 (patch)
tree160f4f9e52676063433f41f278b4d79c481b590c
parent4ecb9bd19cb4259ace677a9878653f52144370d2 (diff)
downloadoslo-db-8e96b95eb58fc02c13c378c6ea7ca96ae51a9164.tar.gz
Adjust SAVEPOINT cause test for SQLA 1.1
SQLAlchemy 1.1 has repaired some of the failure modes for Session.rollback(), including the MySQL case where the savepoint identifier gets lost, such that the Session is in a more usable state than before. A side effect of this is that the test here in oslo.db only hits a single error handler, not two. SQLAlchemy upstream is described at: https://docs.sqlalchemy.org/en/latest/changelog/migration_11.html#improved-session-state-when-a-savepoint-is-cancelled-by-the-database Change-Id: I324f288701e9ffd241de638e0e0419dc8d9c1264
-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(