Skip to content

mapped() : reduce trigger an error if initial value is empty #52

@MrFaBemol

Description

@MrFaBemol

` 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions