From 58ed5199446eaa9412e5b07df8be82fe06253f85 Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Tue, 4 Dec 2012 18:31:04 +0000 Subject: [PATCH] Correctly raise Duplicate exceptions with MySQL. Fixes bug #1083593. Change-Id: Iaa3f32d7acddc7a876dbd5b3d534490aef2d298f --- moniker/storage/impl_sqlalchemy/models.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/moniker/storage/impl_sqlalchemy/models.py b/moniker/storage/impl_sqlalchemy/models.py index 43a74e8a5..65dba6c15 100644 --- a/moniker/storage/impl_sqlalchemy/models.py +++ b/moniker/storage/impl_sqlalchemy/models.py @@ -70,10 +70,17 @@ class Base(object): try: session.flush() except IntegrityError, e: - if 'not unique' in str(e): - raise exceptions.Duplicate(str(e)) - else: - raise + non_unique_strings = ( + 'duplicate entry', + 'not unique' + ) + + for non_unique_string in non_unique_strings: + if non_unique_string in str(e).lower(): + raise exceptions.Duplicate(str(e)) + + # Not a Duplicate error.. Re-raise. + raise def delete(self, session): """ Delete this object """