summaryrefslogtreecommitdiff
path: root/oslo
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2014-08-22 18:17:20 +0200
committerVictor Sergeyev <vsergeyev@mirantis.com>2014-09-05 19:01:59 +0300
commit4ed63fac854361c0e06411ef6f66a9b797c3d042 (patch)
treef6a303b00a9147294c4b1b340be3f5f612f572e2 /oslo
parentbe6f9a0ff7da10bd272c369d97058bf3546fc508 (diff)
downloadoslo-db-4ed63fac854361c0e06411ef6f66a9b797c3d042.tar.gz
Fix DBReferenceError on MySQL and SQLite
It turns out the test was wrong as the error message used was not a good one. Real world tests showed that, so I've updated the test and the code to work. Refactored tests to use real backends, fix error message for SQLite. Co-Authored-By: Victor Sergeyev <vsergeyev@mirantis.com> Change-Id: Ifa64478a9ac9ed0a3c317a8974615b770c85f313
Diffstat (limited to 'oslo')
-rw-r--r--oslo/db/sqlalchemy/exc_filters.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/oslo/db/sqlalchemy/exc_filters.py b/oslo/db/sqlalchemy/exc_filters.py
index c03c4b4..b3da401 100644
--- a/oslo/db/sqlalchemy/exc_filters.py
+++ b/oslo/db/sqlalchemy/exc_filters.py
@@ -169,7 +169,7 @@ def _sqlite_dupe_key_error(integrity_error, match, engine_name, is_disconnect):
@filters("sqlite", sqla_exc.IntegrityError,
- r".*SQL error: foreign key constraint failed")
+ r"(?i).*foreign key constraint failed")
@filters("postgresql", sqla_exc.IntegrityError,
r".*on table \"(?P<table>[^\"]+)\" violates "
"foreign key constraint \"(?P<constraint>[^\"]+)\"\s*\n"
@@ -177,13 +177,13 @@ def _sqlite_dupe_key_error(integrity_error, match, engine_name, is_disconnect):
"is not present in table "
"\"(?P<key_table>[^\"]+)\".")
@filters("mysql", sqla_exc.IntegrityError,
- r".* Cannot add or update a child row: "
- "a foreign key constraint fails "
- "\((?P<table>.+), CONSTRAINT (?P<constraint>.+) "
- "FOREIGN KEY \((?P<key>.+)\) "
- "REFERENCES (?P<key_table>.+) \(.+\)\)")
+ r".* 'Cannot add or update a child row: "
+ 'a foreign key constraint fails \([`"].+[`"]\.[`"](?P<table>.+)[`"], '
+ 'CONSTRAINT [`"](?P<constraint>.+)[`"] FOREIGN KEY '
+ '\([`"](?P<key>.+)[`"]\) REFERENCES [`"](?P<key_table>.+)[`"] ')
def _foreign_key_error(integrity_error, match, engine_name, is_disconnect):
"""Filter for foreign key errors."""
+
try:
table = match.group("table")
except IndexError: