Merge "Correctly raise Duplicate exceptions with MySQL."

This commit is contained in:
Jenkins 2012-12-06 21:21:13 +00:00 committed by Gerrit Code Review
commit 8bb8987ccc

View File

@ -53,10 +53,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 """