diff options
-rw-r--r-- | oslo_db/sqlalchemy/exc_filters.py | 6 | ||||
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_exc_filters.py | 18 |
2 files changed, 23 insertions, 1 deletions
diff --git a/oslo_db/sqlalchemy/exc_filters.py b/oslo_db/sqlalchemy/exc_filters.py index 777fda6..f1f7f88 100644 --- a/oslo_db/sqlalchemy/exc_filters.py +++ b/oslo_db/sqlalchemy/exc_filters.py @@ -91,8 +91,12 @@ def _deadlock_error(operational_error, match, engine_name, is_disconnect): @filters("mysql", sqla_exc.IntegrityError, - r"^.*\b1062\b.*Duplicate entry '(?P<value>[^']+)'" + r"^.*\b1062\b.*Duplicate entry '(?P<value>.+)'" r" for key '(?P<columns>[^']+)'.*$") +# NOTE(jd) For binary types +@filters("mysql", sqla_exc.IntegrityError, + r"^.*\b1062\b.*Duplicate entry \\'(?P<value>.+)\\'" + r" for key \\'(?P<columns>.+)\\'.*$") # NOTE(pkholkin): the first regex is suitable only for PostgreSQL 9.x versions # the second regex is suitable for PostgreSQL 8.x versions @filters("postgresql", sqla_exc.IntegrityError, diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py index aafdcfb..5053754 100644 --- a/oslo_db/tests/sqlalchemy/test_exc_filters.py +++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py @@ -424,6 +424,24 @@ class TestDuplicate(TestsExceptionFilter): expected_value='2' ) + def test_mysql_binary(self): + self._run_dupe_constraint_test( + "mysql", + "(1062, \'Duplicate entry " + "\\\'\\\\x8A$\\\\x8D\\\\xA6\"s\\\\x8E\\\' " + "for key \\\'PRIMARY\\\'\')", + expected_columns=['PRIMARY'], + expected_value="\\\\x8A$\\\\x8D\\\\xA6\"s\\\\x8E" + ) + self._run_dupe_constraint_test( + "mysql", + "(1062, \'Duplicate entry " + "''\\\\x8A$\\\\x8D\\\\xA6\"s\\\\x8E!,' " + "for key 'PRIMARY'\')", + expected_columns=['PRIMARY'], + expected_value="'\\\\x8A$\\\\x8D\\\\xA6\"s\\\\x8E!," + ) + def test_postgresql_single(self): self._run_dupe_constraint_test( 'postgresql', |