summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Benton <kevin@benton.pub>2016-07-05 23:53:37 -0700
committerKevin Benton <kevin@benton.pub>2016-07-05 23:53:37 -0700
commit16886e55bd8fde77f71d75c3c87c2f71ee6dbd4f (patch)
tree655d4c238857c252bfd01a50f19112b0ad6715f6
parent1d7e7e453bd3520a0e2772a094a6ce70ad1fd342 (diff)
downloadoslo-db-16886e55bd8fde77f71d75c3c87c2f71ee6dbd4f.tar.gz
Catch empty value DBDuplicate errors
We can have integrity constraint violations when the value is an empty string. The previous regex for converting these into DBDuplicate exceptions was not considering this case. This adjusts the regex to a 0 or many instead of a 1 or many match for the value and adds a case to a test. Change-Id: Ibf4686f92fcffb8e70ec2735ab878e8849ed37b1 Closes-Bug: #1599086
-rw-r--r--oslo_db/sqlalchemy/exc_filters.py4
-rw-r--r--oslo_db/tests/sqlalchemy/test_exc_filters.py4
2 files changed, 6 insertions, 2 deletions
diff --git a/oslo_db/sqlalchemy/exc_filters.py b/oslo_db/sqlalchemy/exc_filters.py
index 6ab082e..88b214b 100644
--- a/oslo_db/sqlalchemy/exc_filters.py
+++ b/oslo_db/sqlalchemy/exc_filters.py
@@ -91,11 +91,11 @@ 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"^.*\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
diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py
index ac9e35f..6cc4a0b 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -547,6 +547,10 @@ class TestDuplicate(TestsExceptionFilter):
"mysql",
'(1062, "Duplicate entry '
'\'2-3\' for key \'uniq_tbl0a0b\'")', expected_value='2-3')
+ self._run_dupe_constraint_test(
+ "mysql",
+ '(1062, "Duplicate entry '
+ '\'\' for key \'uniq_tbl0a0b\'")', expected_value='')
def test_mysql_mysqlconnector(self):
self._run_dupe_constraint_test(