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:23:11 +0000
commitda8fe0c5a8a3cfe86301329480bd1d2aa1740b93 (patch)
tree757ebf9a147287126d67e7cdfcac8063e4e39ef0
parent7f61fc588d6ffbbd2e304390c46f50708113b941 (diff)
downloadoslo-db-da8fe0c5a8a3cfe86301329480bd1d2aa1740b93.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 4ad6cf2..ea7536d 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 7e6caf4..5ec257e 100644
--- a/oslo_db/tests/sqlalchemy/test_exc_filters.py
+++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py
@@ -511,6 +511,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(