[FIX] temperate error message in case of missing required field
The message worked (ish) for a missing field directly on the model, but completely broke if the missing field was on an o2m and had the same name as a field on the model, then it was complete misinformation. bzr revid: xmo@openerp.com-20121112084804-zcgtpml3a19uv909
This commit is contained in:
+9
-6
@@ -5216,14 +5216,17 @@ 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))
|
||||
if not m or m.group('field') not in fields:
|
||||
field_name = m.group('field')
|
||||
if not m or field_name not in fields:
|
||||
return {'message': unicode(e)}
|
||||
field = fields[m.group('field')]
|
||||
message = _(u"Missing required value for the field '%s'.") % field_name
|
||||
field = fields.get(field_name)
|
||||
if field:
|
||||
message = _(u"%s This might be '%s' in the current model, or a field "
|
||||
u"of the same name in an o2m.") % (message, field['string'])
|
||||
return {
|
||||
'message': _(u"Missing required value for the field '%(field)s'") % {
|
||||
'field': field['string']
|
||||
},
|
||||
'field': m.group('field'),
|
||||
'message': message,
|
||||
'field': field_name,
|
||||
}
|
||||
|
||||
PGERROR_TO_OE = collections.defaultdict(
|
||||
|
||||
@@ -393,14 +393,18 @@ class test_required_string_field(ImporterCase):
|
||||
def test_empty(self):
|
||||
result = self.import_(['value'], [[]])
|
||||
self.assertEqual(result['messages'], [message(
|
||||
u"Missing required value for the field 'unknown'")])
|
||||
u"Missing required value for the field 'value'. This might be "
|
||||
u"'unknown' in the current model, or a field of the same name in "
|
||||
u"an o2m.")])
|
||||
self.assertIs(result['ids'], False)
|
||||
|
||||
@mute_logger('openerp.sql_db', 'openerp.osv.orm')
|
||||
def test_not_provided(self):
|
||||
result = self.import_(['const'], [['12']])
|
||||
self.assertEqual(result['messages'], [message(
|
||||
u"Missing required value for the field 'unknown'")])
|
||||
u"Missing required value for the field 'value'. This might be "
|
||||
u"'unknown' in the current model, or a field of the same name in "
|
||||
u"an o2m.")])
|
||||
self.assertIs(result['ids'], False)
|
||||
|
||||
class test_text(ImporterCase):
|
||||
|
||||
Reference in New Issue
Block a user