Merge lp:~openerp-community/openobject-server/fix-1094212-multicompany-res_partner into lp:openobject-server/7.0

Proposed by Niels Huylebroeck
Status: Merged
Approved by: Xavier ALT
Approved revision: 4762
Merged at revision: 4858
Proposed branch: lp:~openerp-community/openobject-server/fix-1094212-multicompany-res_partner
Merge into: lp:openobject-server/7.0
Diff against target: 13 lines (+1/-2)
1 file modified
openerp/addons/base/res/res_partner.py (+1/-2)
To merge this branch: bzr merge lp:~openerp-community/openobject-server/fix-1094212-multicompany-res_partner
Reviewer Review Type Date Requested Status
Fabien (Open ERP) Needs Fixing
Review via email: mp+141936@code.launchpad.net

Description of the change

The problem:

The result of cr.execute is bad (why hasn't everyone at openerp been brainwashed yet?) because it will contain results not appropriate for the current user (because of un-applied record rules)

The solution:

After we fetched the result cr.execute I now force the search to be executed (unconditionally) which is no problem even if "args" was not passed (see beginning of function where it is set to [] if it was None). Doing this search it will pass all the ids we have found so far but will also apply the required record rules, thus filtering out the unreadable partner ids in the process.

To post a comment you must log in.
Revision history for this message
Fabien (Open ERP) (fp-tinyerp) wrote :

I guess a clean solution would be to completly replace the cr.execute by a self.search, instead of doing two searches. It's also important for performance issues.

review: Needs Fixing
Revision history for this message
Niels Huylebroeck (red15) wrote :

I agree but the current state of affair was that it didn't work for
multicompany setup AND there were already 2 search queries most of the time
anyway (plenty of arguments being passed).

In fact by removing that if statement you could reason I saved time on the
python side, because that check was (almost) redundant anyway.

Revision history for this message
Cloves Almeida (cjalmeida) wrote :

A solution to give an order of magnitude performance speed would be:

a) create a "name_with_company" stored function field on res_partner to avoid the join;

b) create an expression index[1] on "lower(name_with_company)";

c) change the query to use ('lower(%s) like lower(name_with_company)') for ("name","ilike") name_search (about 99% of the case)

d) keep the self.search to apply the record rules - the IN on the database side is a cheap query.

[1] http://www.postgresql.org/docs/9.1/static/indexes-expressional.html

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Pointing to revision 4786 because that is what the MP said that it was merged at before I changed its status. Looks like someone merged the branch but then made manual changes. The effect is that if you try to merge the branch now, bzr says 'Nothing to do'. But the faulty line is still there: http://bazaar.launchpad.net/~openerp/openobject-server/7.0/view/4786/openerp/addons/base/res/res_partner.py#L466

Revision history for this message
Niels Huylebroeck (red15) wrote :

Yes, it seem Fabien himself has merged this branch but forgot to revert it before working on something else (the document management apparently)

This branch from Fabien was then merged by Thibault into the v7.0 branch.

http://imgur.com/kOGTTIM

4762. By Niels Huylebroeck

[FIX] base: allow searching in multicompany environment on res_partner.

Revision history for this message
Niels Huylebroeck (red15) wrote :

Re-pushed with a new unique id to allow real merging this time.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerp/addons/base/res/res_partner.py'
2--- openerp/addons/base/res/res_partner.py 2013-01-14 17:43:55 +0000
3+++ openerp/addons/base/res/res_partner.py 2013-02-25 14:00:33 +0000
4@@ -463,8 +463,7 @@
5 OR partner.name || ' (' || COALESCE(company.name,'') || ')'
6 ''' + operator + ' %(name)s ' + limit_str, query_args)
7 ids = map(lambda x: x[0], cr.fetchall())
8- if args:
9- ids = self.search(cr, uid, [('id', 'in', ids)] + args, limit=limit, context=context)
10+ ids = self.search(cr, uid, [('id', 'in', ids)] + args, limit=limit, context=context)
11 if ids:
12 return self.name_get(cr, uid, ids, context)
13 return super(res_partner,self).name_search(cr, uid, name, args, operator=operator, context=context, limit=limit)