summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorAndrea Grazioso (agr-odoo) <agr@odoo.com>2021-03-29 13:18:31 +0000
committerAndrea Grazioso (agr-odoo) <agr@odoo.com>2021-04-19 08:41:14 +0000
commitf1a5ad5f20bf1b885a3c2dc2248b8fb15b2d6565 (patch)
tree66b5ccba1b5dc68e0dc5de7812248ce387365854 /odoo
parent8fe9f552ed4591795b449f4d1e32e1563ce43ca2 (diff)
[FIX] base: avoid infinite recursion on attachments search
Have a large number of attachments with res_field set Then go to Settings -> Technical -> Attachments -> add a filter "Res Field" is set. You will have traceback. This occur because the `_search` function will omit from results records with res_field set, forcing recursive calls until either we scan the whole table (80 records at a time) or we hit max recursion limit opw-2463634 closes odoo/odoo#69443 X-original-commit: 08fb44a1f8af9684c28c0dd5e82121193d9bef9a Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo')
-rw-r--r--odoo/addons/base/models/ir_attachment.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py
index deb457ba438..df70781f888 100644
--- a/odoo/addons/base/models/ir_attachment.py
+++ b/odoo/addons/base/models/ir_attachment.py
@@ -432,7 +432,9 @@ class IrAttachment(models.Model):
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
# add res_field=False in domain if not present; the arg[0] trick below
# works for domain items and '&'/'|'/'!' operators too
+ discard_binary_fields_attachments = False
if not any(arg[0] in ('id', 'res_field') for arg in args):
+ discard_binary_fields_attachments = True
args.insert(0, ('res_field', '=', False))
ids = super(IrAttachment, self)._search(args, offset=offset, limit=limit, order=order,
@@ -463,8 +465,8 @@ class IrAttachment(models.Model):
continue
# model_attachments = {res_model: {res_id: set(ids)}}
model_attachments[row['res_model']][row['res_id']].add(row['id'])
- # Should not retrieve binary fields attachments
- if row['res_field']:
+ # Should not retrieve binary fields attachments if not explicitly required
+ if discard_binary_fields_attachments and row['res_field']:
binary_fields_attachments.add(row['id'])
if binary_fields_attachments: