diff --git a/odoo/fields.py b/odoo/fields.py index 7670830d770..1bb934cd70c 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1948,15 +1948,21 @@ class Binary(Field): records = cache.get_records_different_from(records, self, cache_value) if not records: return records + if self.store: + # determine records that are known to be not null + not_null = cache.get_records_different_from(records, self, None) + cache.update(records, self, [cache_value] * len(records)) # retrieve the attachments that store the values, and adapt them if self.store: - atts = records.env['ir.attachment'].sudo().search([ - ('res_model', '=', self.model_name), - ('res_field', '=', self.name), - ('res_id', 'in', records.ids), - ]) + atts = records.env['ir.attachment'].sudo() + if not_null: + atts = atts.search([ + ('res_model', '=', self.model_name), + ('res_field', '=', self.name), + ('res_id', 'in', records.ids), + ]) if value: # update the existing attachments atts.write({'datas': value}) diff --git a/odoo/models.py b/odoo/models.py index 66fae078498..96faaa21289 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -3726,6 +3726,8 @@ Record ids: %(records)s for field in self._fields.values(): if field.type in ('one2many', 'many2many'): self.env.cache.set(record, field, ()) + elif field.related and not field.column_type: + self.env.cache.set(record, field, field.convert_to_cache(None, record)) # DLE P123: `test_adv_activity`, `test_message_assignation_inbox`, `test_message_log`, `test_create_mail_simple`, ... # Set `mail.message.parent_id` to False in cache so it doesn't do the useless SELECT when computing the modified of `child_ids` # in other words, if `parent_id` is not set, no other message `child_ids` are impacted.