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-06 13:24:06 +0000
commitda9da8f5b80be2a330654fe25e94e8b59f0e0182 (patch)
tree8266c9347cb909ce25d1cde14284249879597b00
parent54455f4844208b18ecaf39bff7c789fa406f9b06 (diff)
downloadoslo-db-da9da8f5b80be2a330654fe25e94e8b59f0e0182.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 (cherry picked from commit 16886e55bd8fde77f71d75c3c87c2f71ee6dbd4f)
-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 57f8704..49a3526 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 0d75c83..9a942eb 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -508,6 +508,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(