Merge lp:~openerp-groupes/openobject-server/trunk-context-constraints into lp:openobject-server

Proposed by Olivier Ligot on 2011-05-25
Status: Rejected
Rejected by: Antony Lesuisse (OpenERP) on 2011-09-19
Proposed branch: lp:~openerp-groupes/openobject-server/trunk-context-constraints
Merge into: lp:openobject-server
Diff against target: 12 lines (+1/-1)
1 file modified
openerp/osv/ (+1/-1)
To merge this branch: bzr merge lp:~openerp-groupes/openobject-server/trunk-context-constraints
Reviewer Review Type Date Requested Status
Antony Lesuisse (OpenERP) 2011-05-25 Disapprove on 2011-09-19
Review via email:

Description of the change

This patch passes the context as argument when calling objects constraints.
This allow to use the context in constraints.

Note that the proposal is for trunk and not 6.0 as this is an API change (every constraint must now have context as their last argument in their signature).

To post a comment you must log in.
Vo Minh Thu (thu) wrote :

Have you a specific use case for this?

Olivier Ligot (ligot) wrote :

In our modules, we use the context as a placeholder for extra informations needed by a function when the signature can not be changed (ex: constraints).
For example, we use it to store a (time consuming) computed values that we can pass around thanks to the context (see commits and

Vo Minh Thu (thu) wrote :

This comment to let you know we will merge this patch, but we have first to check if all addons handle such an additional argument.

Otherwise, I'm not sure the context is the best place to do caching. It should probably be implemented in the function computing the value.

This does not make sense. Constraints should only depends on the actual data. If you call the constraints multiple times on the same data it must always give the same result and therefore cannot be influenced by context.

review: Disapprove

Unmerged revisions

3428. By Olivier Ligot on 2011-05-25

[IMP] Pass context as argument when calling constraints functions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/osv/'
2--- openerp/osv/ 2011-05-24 10:18:10 +0000
3+++ openerp/osv/ 2011-05-25 12:16:16 +0000
4@@ -926,7 +926,7 @@
5 error_msgs = []
6 for constraint in self._constraints:
7 fun, msg, fields = constraint
8- if not fun(self, cr, uid, ids):
9+ if not fun(self, cr, uid, ids, context=context):
10 # Check presence of __call__ directly instead of using
11 # callable() because it will be deprecated as of Python 3.0
12 if hasattr(msg, '__call__'):