diff --git a/odoo/addons/base/models/ir_attachment.py b/odoo/addons/base/models/ir_attachment.py index a8d5ce90672..deb457ba438 100644 --- a/odoo/addons/base/models/ir_attachment.py +++ b/odoo/addons/base/models/ir_attachment.py @@ -489,11 +489,14 @@ class IrAttachment(models.Model): result = [id for id in orig_ids if id in ids] # If the original search reached the limit, it is important the - # filtered record set does so too. When a JS view recieve a - # record set whose length is bellow the limit, it thinks it - # reached the last page. - if len(orig_ids) == limit and len(result) < len(orig_ids): - result.extend(self._search(args, offset=offset + len(orig_ids), + # filtered record set does so too. When a JS view receive a + # record set whose length is below the limit, it thinks it + # reached the last page. To avoid an infinite recursion due to the + # permission checks the sub-call need to be aware of the number of + # expected records to retrieve + if len(orig_ids) == limit and len(result) < self._context.get('need', limit): + need = self._context.get('need', limit) - len(result) + result.extend(self.with_context(need=need)._search(args, offset=offset + len(orig_ids), limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)[:limit - len(result)])