From f05f8ef647a4eaba49d8a20eb8068f1c7a702297 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Mon, 19 Oct 2020 08:07:43 +0000 Subject: [PATCH] [FIX] base: do not search for attachment for related fields in _binary_record_content Use case: website_event_track(_online) ====================================== On sponsor model, image_128 field is defined in website_event_track module as computed stored Image field. It means that when this binary field is set, an attachment is created in ir.attachment model -> attachment is set to True. In website_event_track_online module this field is modified. It is set as a related (resized) version of image_512 and not stored anymore. However attachments still exist in ir.attachment table for sponsor records. This is not an issue when trying to access the image_128 field using the ORM as the compute (or related) is correctly called. However '/web/image' does checks if the field has an attachment and loads it. In our case old attachments still in database are therefore displayed instead of the new related image. Fix === When checking for an existing attachment in _binary_record_content we also check that the field is not a related. This fixes the current issue. It also makes _binary_record_content work as the ORM, aka using the computed value and not any stored information. DB Cleaning =========== In 14.0 a script will be added to clean existing attachments for sponsor model. Indeed there is no need to keep unused attachments. Especially in 14 website_event_track_online has been merged in website_event_track, meaning only existing db have to be cleaned. New DBs will never have this attachment issue as the field is always computed. Task ID: 2341108 closes odoo/odoo#60259 X-original-commit: ada1eab338c6cffb526b03377ec01962f9c26c4c Signed-off-by: Thibault Delavallee (tde) --- odoo/addons/base/models/ir_http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odoo/addons/base/models/ir_http.py b/odoo/addons/base/models/ir_http.py index 9888337e312..d6152f2e6d5 100644 --- a/odoo/addons/base/models/ir_http.py +++ b/odoo/addons/base/models/ir_http.py @@ -377,7 +377,7 @@ class IrHttp(models.AbstractModel): filehash = 'checksum' in record and record['checksum'] or False field_def = record._fields[field] - if field_def.type == 'binary' and field_def.attachment: + if field_def.type == 'binary' and field_def.attachment and not field_def.related: if model != 'ir.attachment': field_attachment = self.env['ir.attachment'].sudo().search_read(domain=[('res_model', '=', model), ('res_id', '=', record.id), ('res_field', '=', field)], fields=['datas', 'mimetype', 'checksum'], limit=1) if field_attachment: