browse_record prefetching may cause spurious `Access Denied` errors (e.g. after refresh())

Bug #1238042 reported by Stefan Rijnhart (Opener)
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
OpenERP's Framework R&D

Bug Description

To reproduce:

Create a database with two companies, with company B the parent company of company A. Create user for company A.

Set a pdb hook at any point. Trigger the interactive console in a session of the created user. Type the following, where '1' is the id of company A, the company of the current user.

(Pdb) co = self.pool.get('res.company').browse(cr, uid, 1)
(Pdb) co._data.keys()
[1]
(Pdb) co.name
u'Your Company'
(Pdb) co.refresh()
(Pdb) co._data.keys()
[1, 3]
(Pdb) co.name
*** except_orm: (u'Access Denied', u'The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: Companies, Operation: read)')

Analysis:

You see in the output of the interactive session that the id of the parent company ends up in the browse record _data dictionary. When you read out the name of the company again, an attempt will be made to read all the companies in this dictionary. This will lead to an access error because the user does not have permisions on the parent company.

Related branches

summary: Access denied after refresh of a res.company browse record with parent
- companyefresh()
+ company
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote : Re: Access denied after refresh of a res.company browse record with parent company

Hi Twinkle Christian,

you marked this bug as a duplicate of lp:1212429. However, according to the suggested fix the problem there is merely that a lookup is performed to the warehouse with id 'stock.warehouse0', which could belong to a different company than the current company of the user. This bug concerns a fundamental flaw in the browse record cache. I am unmarking the duplicate.

summary: - Access denied after refresh of a res.company browse record with parent
- company
+ browse_record prefetching may cause spurious `Access Denied` errors
+ (e.g. after refresh())
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

A fix for this issue has landed in 7.0 server at revision 5136 rev-id: <email address hidden>

This rather tricky issue is fixed by trying to detect the cases where the prefetching system causes an "artificial" access error. When that happens, the operation is retried only for the record being browsed, effectively turning off prefetching. As the bug occurred rather seldom, this should hopefully not affect average performance in a significant way. However when it happens, prefetching is silently disabled, and further use of the affected browse_records may be slower. This may or may not be desirable, depending on occurrence frequency.
Watching the log for INFO entries "Prefetching attempt for fields [..] on [model] failed..." should tell us if that happens too often.

Stefan, thanks again for reporting and working on a patch for this undesirable behavior!

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
milestone: none → 7.0
status: New → Fix Released
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Olivier, thanks for picking this up and fixing it in a performant way!

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.