summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Konovalov <nkonovalov@mirantis.com>2013-12-11 12:35:54 (GMT)
committerNikita Konovalov <nkonovalov@mirantis.com>2013-12-17 13:00:51 (GMT)
commitc802fa66f85df1c18c35b355088b24c2040b51f5 (patch)
treeb7e3fd54a166fbb1d807157f5f1fac02b8b9851a
parent15ea4ffdbcc59e105ba93e6166bf4a0725c55acf (diff)
SQLAlchemy error patterns improvedrefs/changes/05/61405/2
SQLite has new error messages since 3.7.16. DBDuplicateEntry is now recognized correctly. Change-Id: I86e9673ac409b3b3e881bea7cb8b3516f320388d Fixes: bug #1259915
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Julien Danjou <julien@danjou.info> Code-Review+1: Sean M. Collins <sean_collins2@cable.comcast.com> Approved+1: Davanum Srinivas (dims) <davanum@gmail.com> Code-Review+2: Davanum Srinivas (dims) <davanum@gmail.com> Code-Review+1: ChangBo Guo <guochbo@cn.ibm.com> Code-Review+1: Sergey Lukjanov <slukjanov@mirantis.com> Submitted-by: Jenkins Submitted-at: Sun, 22 Dec 2013 02:03:22 +0000 Reviewed-on: https://review.openstack.org/61405 Project: openstack/oslo-incubator Branch: refs/heads/master
-rw-r--r--openstack/common/db/sqlalchemy/session.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/openstack/common/db/sqlalchemy/session.py b/openstack/common/db/sqlalchemy/session.py
index c82809d..790ce59 100644
--- a/openstack/common/db/sqlalchemy/session.py
+++ b/openstack/common/db/sqlalchemy/session.py
@@ -439,6 +439,11 @@ def get_session(autocommit=True, expire_on_commit=False,
439# 1 column - (IntegrityError) column c1 is not unique 439# 1 column - (IntegrityError) column c1 is not unique
440# N columns - (IntegrityError) column c1, c2, ..., N are not unique 440# N columns - (IntegrityError) column c1, c2, ..., N are not unique
441# 441#
442# sqlite since 3.7.16:
443# 1 column - (IntegrityError) UNIQUE constraint failed: k1
444#
445# N columns - (IntegrityError) UNIQUE constraint failed: k1, k2
446#
442# postgres: 447# postgres:
443# 1 column - (IntegrityError) duplicate key value violates unique 448# 1 column - (IntegrityError) duplicate key value violates unique
444# constraint "users_c1_key" 449# constraint "users_c1_key"
@@ -451,9 +456,10 @@ def get_session(autocommit=True, expire_on_commit=False,
451# N columns - (IntegrityError) (1062, "Duplicate entry 'values joined 456# N columns - (IntegrityError) (1062, "Duplicate entry 'values joined
452# with -' for key 'name_of_our_constraint'") 457# with -' for key 'name_of_our_constraint'")
453_DUP_KEY_RE_DB = { 458_DUP_KEY_RE_DB = {
454 "sqlite": re.compile(r"^.*columns?([^)]+)(is|are)\s+not\s+unique$"), 459 "sqlite": (re.compile(r"^.*columns?([^)]+)(is|are)\s+not\s+unique$"),
455 "postgresql": re.compile(r"^.*duplicate\s+key.*\"([^\"]+)\"\s*\n.*$"), 460 re.compile(r"^.*UNIQUE\s+constraint\s+failed:\s+(.+)$")),
456 "mysql": re.compile(r"^.*\(1062,.*'([^\']+)'\"\)$") 461 "postgresql": (re.compile(r"^.*duplicate\s+key.*\"([^\"]+)\"\s*\n.*$"),),
462 "mysql": (re.compile(r"^.*\(1062,.*'([^\']+)'\"\)$"),)
457} 463}
458 464
459 465
@@ -483,10 +489,14 @@ def _raise_if_duplicate_entry_error(integrity_error, engine_name):
483 # SQLAlchemy can differ when using unicode() and accessing .message. 489 # SQLAlchemy can differ when using unicode() and accessing .message.
484 # An audit across all three supported engines will be necessary to 490 # An audit across all three supported engines will be necessary to
485 # ensure there are no regressions. 491 # ensure there are no regressions.
486 m = _DUP_KEY_RE_DB[engine_name].match(integrity_error.message) 492 for pattern in _DUP_KEY_RE_DB[engine_name]:
487 if not m: 493 match = pattern.match(integrity_error.message)
494 if match:
495 break
496 else:
488 return 497 return
489 columns = m.group(1) 498
499 columns = match.group(1)
490 500
491 if engine_name == "sqlite": 501 if engine_name == "sqlite":
492 columns = columns.strip().split(", ") 502 columns = columns.strip().split(", ")