From e54317cfcabbb23efab45adb7efb483c2494b38d Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Sun, 22 Dec 2013 10:24:05 +0100 Subject: [PATCH] Improve error messages by showing the failing value issue3489 review1671002 --- CHANGELOG | 1 + trytond/ir/translation.xml | 36 +++++++++++++++++------------------ trytond/model/modelsql.py | 12 ++++++------ trytond/model/modelstorage.py | 34 ++++++++++++++++++++++----------- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 294d1a332b..c6e6e26405 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Improve error messages by showing the failing value * Remove relation field actions: - delete_all - unlink_all diff --git a/trytond/ir/translation.xml b/trytond/ir/translation.xml index 5c57717212..7e4e6f0aa9 100644 --- a/trytond/ir/translation.xml +++ b/trytond/ir/translation.xml @@ -109,8 +109,8 @@ this repository contains the full copyright notices and license terms. --> domain_validation_record en_US error - The value of the field "%s" on "%s" is not valid according to its domain. - The value of the field "%s" on "%s" is not valid according to its domain. + The value of the field "%(field)s" on "%(model)s" is not valid according to its domain. + The value of the field "%(field)s" on "%(model)s" is not valid according to its domain. ir @@ -118,8 +118,8 @@ this repository contains the full copyright notices and license terms. --> required_validation_record en_US error - The field "%s" on "%s" is required. - The field "%s" on "%s" is required. + The field "%(field)s" on "%(model)s" is required. + The field "%(field)s" on "%(model)s" is required. ir @@ -127,8 +127,8 @@ this repository contains the full copyright notices and license terms. --> size_validation_record en_US error - The field "%s" on "%s" is too long. - The field "%s" on "%s" is too long. + The size "%(size)s" of the field "%(field)s" on "%(model)s" is too long. + The size "%(size)s" of the field "%(field)s" on "(model)%s" is too long. ir @@ -136,8 +136,8 @@ this repository contains the full copyright notices and license terms. --> digits_validation_record en_US error - The field "%s" on "%s" has too many decimal digits. - The field "%s" on "%s" has too many decimal digits. + The number of digits "%(digits)s" of field "%(field)s" on "%(value)s" exceeds it's limit. + The number of digits "%(digits)s" of field "%(field)s" on "%(value)s" exceeds it's limit. ir @@ -146,8 +146,8 @@ this repository contains the full copyright notices and license terms. --> selection_validation_record en_US error - The field "%s" on "%s" is not in the selection. - The field "%s" on "%s" is not in the selection. + The value "%(value)s" of field "%(field)s" on "%(model)s" is not in the selection. + The value "%(value)s" of field "%(field)s" on "%(model)s" is not in the selection. ir @@ -155,8 +155,8 @@ this repository contains the full copyright notices and license terms. --> time_format_validation_record en_US error - The time value of field "%s" on "%s" is not valid. - The time value of field "%s" on "%s" is not valid. + The time value "%(value)s" of field "%(field)s" on "%(model)s" is not valid. + The time value "%(value)s" of field "%(field)s" on "%(model)s" is not valid. ir @@ -197,8 +197,8 @@ this repository contains the full copyright notices and license terms. --> required_field en_US error - The field "%s" on "%s" is required. - The field "%s" on "%s" is required. + The field "%(field)s" on "%(model)s" is required. + The field "%(field)s" on "%(model)s" is required. ir @@ -206,8 +206,8 @@ this repository contains the full copyright notices and license terms. --> foreign_model_missing en_US error - The value of field "%s" on "%s" doesn't exist. - The value of field "%s" on "%s" doesn't exist. + The value "%(value)s" of field "%(field)s" on "%(model)s" doesn't exist. + The value "%(value)s" of field "%(field)s" on "%(model)s" doesn't exist. ir @@ -215,8 +215,8 @@ this repository contains the full copyright notices and license terms. --> foreign_model_exist en_US error - Could not delete "%s" records because they are used on field "%s" of "%s". - Could not delete "%s" records because they are used on field "%s" of "%s". + Could not delete "%(value)s" records because they are used on field "%(field)s" of "%(model)s". + Could not delete "%(value)s" records because they are used on field "%(field)s" of "%(model)s". ir diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 756035cca0..007757e1d1 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -218,8 +218,10 @@ class ModelSQL(ModelStorage): if not ((target_records or (values[field_name] in create_records)) and (values[field_name] not in delete_records)): + error_args = cls._get_error_args(field_name) + error_args['value'] = values[field_name] cls.raise_user_error('foreign_model_missing', - error_args=cls._get_error_args(field_name)) + error_args=error_args) for name, _, error in cls._sql_constraints: if name in exception[0]: cls.raise_user_error(error) @@ -839,12 +841,10 @@ class ModelSQL(ModelStorage): if Model.search([ (field_name, 'in', sub_ids), ], order=[]): - error_args = [] - error_args.append(cls._get_error_args('id')[1]) - error_args.extend(list( - Model._get_error_args(field_name))) + error_args = Model._get_error_args(field_name) + error_args['value'] = cls._get_error_args('id')[1] cls.raise_user_error('foreign_model_exist', - error_args=tuple(error_args)) + error_args=error_args) super(ModelSQL, cls).delete(sub_records) diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 9429dd8ecd..e59c2fbed1 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -849,7 +849,10 @@ class ModelStorage(Model): def _get_error_args(cls, field_name): pool = Pool() ModelField = pool.get('ir.model.field') - error_args = (field_name, cls.__name__) + error_args = { + 'field': field_name, + 'model': cls.__name__ + } if ModelField: model_fields = ModelField.search([ ('name', '=', field_name), @@ -857,8 +860,10 @@ class ModelStorage(Model): ], limit=1) if model_fields: model_field, = model_fields - error_args = (model_field.field_description, - model_field.model.name) + error_args.update({ + 'field': model_field.field_description, + 'model': model_field.model.name, + }) return error_args @classmethod @@ -1023,16 +1028,19 @@ class ModelStorage(Model): field_size = PYSONDecoder(env).decode(pyson_size) else: field_size = field.size - if (len(getattr(record, field_name) or '') - > field_size >= 0): - cls.raise_user_error( - 'size_validation_record', - error_args=cls._get_error_args(field_name)) + size = len(getattr(record, field_name) or '') + if (size > field_size >= 0): + error_args = cls._get_error_args(field_name) + error_args['size'] = size + cls.raise_user_error('size_validation_record', + error_args=error_args) def digits_test(value, digits, field_name): def raise_user_error(): + error_args = cls._get_error_args(field_name) + error_args['digits'] = digits[1] cls.raise_user_error('digits_validation_record', - error_args=cls._get_error_args(field_name)) + error_args=error_args) if value is None: return if isinstance(value, Decimal): @@ -1084,8 +1092,10 @@ class ModelStorage(Model): test.add('') test.add(None) if value not in test: + error_args = cls._get_error_args(field_name) + error_args['value'] = value cls.raise_user_error('selection_validation_record', - error_args=cls._get_error_args(field_name)) + error_args=error_args) def format_test(value, format, field_name): if not value: @@ -1094,8 +1104,10 @@ class ModelStorage(Model): value = value.time() if value != datetime.datetime.strptime( value.strftime(format), format).time(): + error_args = cls._get_error_args(field_name) + error_args['value'] = value cls.raise_user_error('time_format_validation_record', - error_args=cls._get_error_args(field_name)) + error_args=error_args) # validate time format if (field._type in ('datetime', 'time')