check no match result in convert_pgerror_* functions

This commit is contained in:
kevin wang 2014-05-17 22:55:51 +08:00
parent 59354d5bf3
commit b1dfb8e193
1 changed files with 2 additions and 2 deletions

View File

@ -5217,7 +5217,7 @@ def convert_pgerror_23502(model, fields, info, e):
m = re.match(r'^null value in column "(?P<field>\w+)" violates '
r'not-null constraint\n',
str(e))
field_name = m.group('field')
field_name = m and m.group('field')
if not m or field_name not in fields:
return {'message': unicode(e)}
message = _(u"Missing required value for the field '%s'.") % field_name
@ -5232,7 +5232,7 @@ def convert_pgerror_23502(model, fields, info, e):
def convert_pgerror_23505(model, fields, info, e):
m = re.match(r'^duplicate key (?P<field>\w+) violates unique constraint',
str(e))
field_name = m.group('field')
field_name = m and m.group('field')
if not m or field_name not in fields:
return {'message': unicode(e)}
message = _(u"The value for the field '%s' already exists.") % field_name