[FIX] fields: do not revalidate field values unless they are being modified
authorOlivier Dony <odo@openerp.com>
Wed, 23 Jul 2014 10:30:24 +0000 (12:30 +0200)
committerOlivier Dony <odo@openerp.com>
Wed, 23 Jul 2014 10:30:24 +0000 (12:30 +0200)
commit8974e928fa9f9b54ef3fbaf685aedbcccd2c755d
treed6836ed019b0b3d8bfc40a22466a3e0c267aa282
parent42f3575bb3fdc6c0b2a5c43685d7bd99d771f2fd
[FIX] fields: do not revalidate field values unless they are being modified

In the previous implementation of the new API fields,
both fields.Selection and fields.Reference were performing
early validation of their `value` as soon as it entered
the cache, either by being read, written, or computed.
This is a source of trouble and performance problems,
and is unnecessary, as we should consider that the database
always contains valid values. If that is not the case it
means it was modified externally and is an exception that
should be handled externally as well.

Revalidating selection/reference values can be expensive
when the domain of values is dynamic and requires extra
database queries, with extra access rights control, etc.

This patch adds a `validate` parameter to `convert_to_cache`,
allowing to turn off the re-validation on demand. The ORM
will turn off validation whenever the value being converted
is supposed to be already validated, such as when reading it
from the database.
The parameter is currently ignored by all other fields,
and defaults to True so validation is performed in all other
caes.
openerp/fields.py
openerp/models.py