` def mapped(self, field: str):
""" Perform a read only if any of the record has dirty cache """
if not self.env.cache_enabled or self.cache_expired(field):
read_res = self.read([field])
if not self.env.cache_enabled:
self.env.logger.warning(f"With cache disabled, the result of mapped() is quite different from Odoo's behavior in case of relational fields. It only returns a list with raw results from API for now.")
return [rec.get(field) for rec in read_res]
res = [getattr(rec, field) for rec in self]
# Return a recordset if the field is relational
if is_relational_field(self.get_field_info(field, 'type')):
res = reduce(lambda a, b: a | b, res)
res = res.with_context(**self.context)
return res`
The reduce here should check for null value otherwise we could get an error
` def mapped(self, field: str):
""" Perform a read only if any of the record has dirty cache """
if not self.env.cache_enabled or self.cache_expired(field):
read_res = self.read([field])
if not self.env.cache_enabled:
self.env.logger.warning(f"With cache disabled, the result of mapped() is quite different from Odoo's behavior in case of relational fields. It only returns a list with raw results from API for now.")
return [rec.get(field) for rec in read_res]
The reduce here should check for null value otherwise we could get an error