commit d6cd25122a88de784cc5e22e69287c8f1c1a06e6 Author: Koichiro Den Date: Thu Oct 1 17:16:01 2020 +0900 Workaround for unsuccessfully parsed duplicate key error Since MySQL server 8.0.19, the table name is prepended to the key name in duplicate key error messages. For now, oslo_db exception filter fails to successfully parse them, leading to some functional test failures. Once the issue is resolved, this patch will become unnecessary. Change-Id: I92e43fd71b1affcedfcb807205e89687b17161da Closes-bug: #1896867 diff --git a/tacker/common/exceptions.py b/tacker/common/exceptions.py index b20efed..be0232d 100644 --- a/tacker/common/exceptions.py +++ b/tacker/common/exceptions.py @@ -17,6 +17,8 @@ Tacker base exception handling. """ +import re + from oslo_log import log as logging import webob.exc from webob import util as woutil @@ -206,6 +208,18 @@ class DuplicateResourceName(TackerException): class DuplicateEntity(Conflict): message = _("%(_type)s already exist with given %(entry)s") + def __init__(self, *args, **kwargs): + # oslo.db does not parse duplicate key error correctly + # if MySQL server is >=8.0.19. (oslo.db BUG 1896916) + # TODO(kden): revert once the issue is resolved. + if len(kwargs["entry"]) == 1: + matched = re.match( + r"(?P[^\.]+)\.uniq_(?P=tbl)0(?P.+)$", + kwargs["entry"][0]) + if matched is not None: + kwargs["entry"] = matched.group("columns").split("0") + super(DuplicateEntity, self).__init__(*args, **kwargs) + class ValidationError(BadRequest): message = "%(detail)s"