From ece40d83fb84fd135103c891d907a935f3eb13da Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Wed, 14 Oct 2020 12:44:26 +0000 Subject: [PATCH] [FIX] doc: warn about pitfalls of inverse batching This commit updates the documentation surrounding compute and inverse methods for fields, explicitly warning API consumers that grouping multiple compute fields under a single inverse method is error-prone and could not work at all (it can still work under specific conditions but henceforth it shall be considered bad practice). This case was found at https://github.com/odoo/enterprise/pull/13815/commits/a651413df915f166697d26a83084582207405858 closes odoo/odoo#60115 X-original-commit: 1d21924c1da0bed59cd105a3d9bf9b60fa2d7bc4 Signed-off-by: Raphael Collet (rco) Signed-off-by: Adrian Torres (adt) --- doc/reference/orm.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/reference/orm.rst b/doc/reference/orm.rst index 7d2b3bd1ac6..3ca49846fb6 100644 --- a/doc/reference/orm.rst +++ b/doc/reference/orm.rst @@ -302,6 +302,22 @@ it uses the values of other *fields*, it should specify those fields using record.discount_value = discount record.total = record.value - discount +.. warning:: + + While it is possible to use the same compute method for multiple + fields, it is not recommended to do the same for the inverse + method. + + During the computation of the inverse, **all** fields that use + said inverse are protected, meaning that they can't be computed, + even if their value is not in the cache. + + If any of those fields is accessed and its value is not in cache, + the ORM will simply return a default value of `False` for these fields. + This means that the value of the inverse fields (other than the one + triggering the inverse method) may not give their correct value and + this will probably break the expected behavior of the inverse method. + .. _reference/fields/related: Related fields