[FIX] models: unexpected missing value when checking for a field in cache

At the end of _prefetch_field(), a check is made to ensure that the cache
contains something for the field to prefetch. The check was incorrect because
the cache was checked for a regular value only.
This commit is contained in:
Raphael Collet 2014-08-18 11:50:24 +02:00
parent c1be4a316e
commit 62b0d99cfe
1 changed files with 8 additions and 2 deletions

View File

@ -3148,11 +3148,11 @@ class BaseModel(object):
pass
# check the cache, and update it if necessary
if field not in self._cache:
if not self._cache.contains(field):
for values in result:
record = self.browse(values.pop('id'))
record._cache.update(record._convert_to_cache(values, validate=False))
if field not in self._cache:
if not self._cache.contains(field):
e = AccessError("No value found for %s.%s" % (self, field.name))
self._cache[field] = FailedValue(e)
@ -5677,6 +5677,12 @@ class RecordCache(MutableMapping):
def __init__(self, records):
self._recs = records
def contains(self, field):
""" Return whether `records[0]` has a value for `field` in cache. """
if isinstance(field, basestring):
field = self._recs._fields[field]
return self._recs.id in self._recs.env.cache[field]
def __contains__(self, field):
""" Return whether `records[0]` has a regular value for `field` in cache. """
if isinstance(field, basestring):