diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-04-09 15:51:44 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-04-09 15:51:44 +0000 |
commit | 7e747bf3633755629ce2166619e48f57c01acef9 (patch) | |
tree | 45a02f4e1c4d195d48af2188b4ffc7bd2a9a8a40 /oslo_db | |
parent | e95e8ef78297f0b9e4283278e4eed3fc9ef9a5fb (diff) | |
parent | 3522ef758a58fed18bb2b1b210018d4f8a3bbb6d (diff) | |
download | oslo-db-7e747bf3633755629ce2166619e48f57c01acef9.tar.gz |
Merge "Catch DBDuplicateError in MySQL if primary key is binary"
Diffstat (limited to 'oslo_db')
-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', |