From be03940d64800e5adc0789e419e606252c3f5cf5 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 12 Nov 2012 09:48:04 +0100 Subject: [PATCH] [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 --- openerp/osv/orm.py | 15 +++++++++------ .../tests/addons/test_impex/tests/test_load.py | 8 ++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index c8f4941b1a2..3003119bc41 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -5216,14 +5216,17 @@ def convert_pgerror_23502(model, fields, info, e): m = re.match(r'^null value in column "(?P\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( diff --git a/openerp/tests/addons/test_impex/tests/test_load.py b/openerp/tests/addons/test_impex/tests/test_load.py index 9ef2a43dec9..7c56ab78bbd 100644 --- a/openerp/tests/addons/test_impex/tests/test_load.py +++ b/openerp/tests/addons/test_impex/tests/test_load.py @@ -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):