Invalid lookup in ormcache()

Bug #988743 reported by Thibaut DIRLIK (Logica)
18
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Medium
OpenERP's Framework R&D

Bug Description

Hi,

In ormcache(), you check if the data is present using the "key" variable, and you define it using "args" [1], which is not the same. The first one is based on self.skiparg, whereas the second is not.

So, for decorators which set the "skiparg" arguments, if it is different of 2, the cache won't work. The fix is simply to set d[key] inseatd of d[args].

[1] : http://bazaar.launchpad.net/~openerp/openobject-server/trunk/view/head:/openerp/tools/cache.py#L46

Related branches

summary: - Invalid lookoop in ormcache()
+ Invalid lookup in ormcache()
Revision history for this message
Jignesh Rathod(OpenERP) (jir-openerp) wrote :

Hello Thibaut DIRLIK ,

I have checked this issue at my end. in ormcache() in lookup() method , Line 41
r = d[key] if it cause KeyError then it handle by except KeyError:
line 46 " value = d[args] = self.method(self2, cr, *args)".
but I did not face any problem regarding this issue.

So would you please elaborate more regarding this issue.

Thanks and waiting for reply!

Changed in openobject-server:
status: New → Incomplete
Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) wrote :

In fact, the problem is the following :

1) You check if the data already is in the cache : d[key]
2) If it's the case, you return it.
3) If it's not the case, you get the value, and save it in the dictionnary "d".

The problem is that when you save the value, you set d[args] instead of d[key]. So, imagine :

key = 'a'
args 'b'

d[key] => Not cached
Then
d[args] = Result => THIS IS WRONG ! It should be d[key] = Result !

In our case, args is the same than key if self.skipargs = 2. However, if self.skipargs is defferent than 2, they won't be the same, and the value will never get cached correctly.

Changed in openobject-server:
status: Incomplete → New
Revision history for this message
Jignesh Rathod(OpenERP) (jir-openerp) wrote :

Hello Thibaut ,

I have checked this again but as your comment #2 I am not getting any problem
regarding this issue.As per line 46 value = d[args] = self.method(self2, cr, *args).
set result value , d[args] by self.method(self2, cr, *args).
means if a = b = c then it set a =c and b = c , So d[args] does not change return value.
So would you please provide proper test case to reproduce this issue.
Or provide a video related to bug.

Thanks and waiting reply!

Changed in openobject-server:
status: New → Incomplete
Revision history for this message
Thibaut DIRLIK (Logica) (thibaut-dirlik) wrote :

I'm sorry, you don't understand what's the problem.

You set a value in the cache using a key (d[key]) and you use an other key (d[args]) to check if it is present in the cache. The "args" variable is based on the "skipargs" arguments, whereas the "key" variable is not.

Pseudo code:

if key not in d:
    d[args] = VALUE

If key != args, the cache won't work.

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hello,

Thibaut is perfectly right, this is apparently a typo that makes the system store cached data with the wrong key whenever skiparg != 2. This basically disables the cache and makes it useless for those cases.
In particular our translation system is affected, because ir.transalation.get_source() uses skiparg=3, so it means the cache does not work for translations at the moment.
This should not cause any bug, but makes the cache system useless in those cases, and might have an impact on performance.

Jignesh, if you want to convince yourself the easiest method is probably to add a print statement after line 46 of tools.cache, and then open any menu in your OpenERP client (e.g Customer list). When you click on the same menu again you should not see any printed lines because all translations should be cached... but in fact you will see them again, and every time you refresh.
Now if you replace d[args] with d[key] on line 46 and try again, you will see that it works as expected.

The fix will be applied soon, however I'd love to have a unit test for this... writing one is quite easy as we have a cache miss counter already.

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
status: Incomplete → Confirmed
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

The fix has landed in 6.1 at revision 4175 rev-id: <email address hidden>.
It will be ported to trunk next time 6.1 is merged.

(It also revealed a cache invalidation bug in the decimal_precision module, fixed in addons at rev.6807 rev-id: <email address hidden>)

Changed in openobject-server:
milestone: none → 6.1
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

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