Validate only modified and dependant fields on model write
issue3445 review1371002
This commit is contained in:
1 parent
a371793507
commit
390f196559
3 files changed
+10
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user