From 390f196559fa73301e18659c7ac2ffc129a7c658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 23 Dec 2013 20:47:25 +0100 Subject: [PATCH] Validate only modified and dependant fields on model write issue3445 review1371002 --- CHANGELOG | 1 + trytond/model/modelsql.py | 4 +++- trytond/model/modelstorage.py | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index c6e6e26405..e0469e7202 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Validate only modified and dependant fields on model write * Improve error messages by showing the failing value * Remove relation field actions: - delete_all diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 3b5873979e..6e706db0a6 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -643,6 +643,7 @@ class ModelSQL(ModelStorage): assert not len(args) % 2 all_records = sum(((records, values) + args)[0:None:2], []) all_ids = [r.id for r in all_records] + all_field_names = set() # Call before cursor cache cleaning trigger_eligibles = cls.trigger_write_get_eligibles(records) @@ -719,9 +720,10 @@ class ModelSQL(ModelStorage): field_names = cls._fields.keys() cls._update_mptt(field_names, [ids] * len(field_names), values) + all_field_names |= set(values.keys()) cls.__insert_history(all_ids) - cls._validate(all_records) + cls._validate(all_records, field_names=all_field_names) cls.trigger_write(trigger_eligibles) @classmethod diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index e59c2fbed1..463be4222d 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -871,7 +871,7 @@ class ModelStorage(Model): pass @classmethod - def _validate(cls, records): + def _validate(cls, records, field_names=None): pool = Pool() # Ensure that records are readable with Transaction().set_user(0, set_context=True): @@ -917,9 +917,14 @@ class ModelStorage(Model): return True return False + field_names = set(field_names or []) ctx_pref['active_test'] = False with Transaction().set_context(ctx_pref): for field_name, field in cls._fields.iteritems(): + if (field_names + and field_name not in field_names + and not (set(field.depends) & field_names)): + continue if isinstance(field, fields.Function) and \ not field.setter: continue