summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Harney <eharney@redhat.com>2016-01-11 11:44:50 -0500
committerEric Harney <eharney@redhat.com>2016-01-25 15:54:28 -0500
commit0a2881e9f5966bf0763d9613442eba2e80fa86e3 (patch)
tree0ee7881742a8695680eafde0ff44c5967d0ac70e
parent021e450fca48ac3fae4c60bba4d33758367a307d (diff)
downloadoslo-db-0a2881e9f5966bf0763d9613442eba2e80fa86e3.tar.gz
Add exc_filter for invalid Unicode string
This error occurs if passing a Unicode string to the database which cannot be stored (i.e. it contains chars >4 bytes long and the db is not configured to handle that). Change-Id: I12311909dec6e447c93917a5efd68599f35c4b89 Related-Bug: #1393871
-rw-r--r--oslo_db/sqlalchemy/exc_filters.py2
-rw-r--r--oslo_db/tests/sqlalchemy/test_exc_filters.py25
2 files changed, 27 insertions, 0 deletions
diff --git a/oslo_db/sqlalchemy/exc_filters.py b/oslo_db/sqlalchemy/exc_filters.py
index 57f8704..4ad6cf2 100644
--- a/oslo_db/sqlalchemy/exc_filters.py
+++ b/oslo_db/sqlalchemy/exc_filters.py
@@ -280,6 +280,8 @@ def _raise_mysql_table_doesnt_exist_asis(
r".*1265.*Data truncated for column.*")
@filters("mysql", sqla_exc.DataError,
r".*1264.*Out of range value for column.*")
+@filters("mysql", sqla_exc.InternalError,
+ r"^.*1366.*Incorrect string value:*")
def _raise_data_error(error, match, engine_name, is_disconnect):
"""Raise DBDataError exception for different data errors."""
diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py
index 0d75c83..7e6caf4 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -77,6 +77,9 @@ class TestsExceptionFilter(_SQLAExceptionMatcher, oslo_test_base.BaseTestCase):
"""
+ class DataError(Error):
+ pass
+
class OperationalError(Error):
pass
@@ -694,6 +697,28 @@ class TestDeadlock(TestsExceptionFilter):
)
+class TestDataError(TestsExceptionFilter):
+ def _run_bad_data_test(self, dialect_name, message, error_class):
+ self._run_test(dialect_name,
+ "INSERT INTO TABLE some_values",
+ error_class(message),
+ exception.DBDataError)
+
+ def test_bad_data_incorrect_string(self):
+ # Error sourced from https://bugs.launchpad.net/cinder/+bug/1393871
+ self._run_bad_data_test("mysql",
+ '(1366, "Incorrect string value: \'\\xF0\' '
+ 'for column \'resource\' at row 1"',
+ self.OperationalError)
+
+ def test_bad_data_out_of_range(self):
+ # Error sourced from https://bugs.launchpad.net/cinder/+bug/1463379
+ self._run_bad_data_test("mysql",
+ '(1264, "Out of range value for column '
+ '\'resource\' at row 1"',
+ self.DataError)
+
+
class IntegrationTest(test_base.DbTestCase):
"""Test an actual error-raising round trips against the database."""