From 0a2881e9f5966bf0763d9613442eba2e80fa86e3 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Mon, 11 Jan 2016 11:44:50 -0500 Subject: 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 --- oslo_db/sqlalchemy/exc_filters.py | 2 ++ oslo_db/tests/sqlalchemy/test_exc_filters.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) 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.""" -- cgit v1.2.1