summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
authorVictor Sergeyev <vsergeyev@mirantis.com>2013-05-21 11:16:42 +0300
committerVictor Sergeyev <vsergeyev@mirantis.com>2013-05-28 15:03:51 +0300
commit3286ca90351d01b08aa6c66e8e3644fb1787a7fe (patch)
tree6b4ce4f4311113216c67c463ad84bd12cc407933 /openstack/common
parentdf7ea8308363235afba503f8562341bd2e3dce4f (diff)
downloadoslo-3286ca90351d01b08aa6c66e8e3644fb1787a7fe.tar.gz
oslo-3286ca90351d01b08aa6c66e8e3644fb1787a7fe.tar.xz
oslo-3286ca90351d01b08aa6c66e8e3644fb1787a7fe.zip
Changed processing unique constraint name.
Function `_raise_if_duplicate_entry_error()` modified respectively to new unique constraint name convention. We found that current constraint name convention allows us create constraints with duplicate names. It happens if we will add constraints in different tables with same column names (for example, `name`, `deleted`). In this case we can not create new constraint due to mysql limitation (it requires unique constraint name for database) To solve this issue unique constraint name convention was changed from "uniq_c1_x_c2_x_c3" to "uniq_t$c1$c2$c3" where `t` it is table name and columns `c1`, `c2`, `c3` are in UniqueConstraint. Function `_raise_if_duplicate_entry_error()` parse error from database and provides us correct column names in error message. So now we receive correct error message from function. Change-Id: I4a507deba97c499fcd9738d980e36ca0f9454b71 Fixes: bug 1182054
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/db/sqlalchemy/session.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/openstack/common/db/sqlalchemy/session.py b/openstack/common/db/sqlalchemy/session.py
index a66ce9f..5eaa258 100644
--- a/openstack/common/db/sqlalchemy/session.py
+++ b/openstack/common/db/sqlalchemy/session.py
@@ -388,14 +388,15 @@ def _raise_if_duplicate_entry_error(integrity_error, engine_name):
"""
def get_columns_from_uniq_cons_or_name(columns):
- # note(boris-42): UniqueConstraint name convention: "uniq_c1_x_c2_x_c3"
- # means that columns c1, c2, c3 are in UniqueConstraint.
+ # note(vsergeyev): UniqueConstraint name convention: "uniq_t$c1$c2"
+ # where `t` it is table name and columns `c1`, `c2`
+ # are in UniqueConstraint.
uniqbase = "uniq_"
if not columns.startswith(uniqbase):
if engine_name == "postgresql":
return [columns[columns.index("_") + 1:columns.rindex("_")]]
return [columns]
- return columns[len(uniqbase):].split("_x_")
+ return columns[len(uniqbase):].split("$")[1:]
if engine_name not in ["mysql", "sqlite", "postgresql"]:
return