[FIX] Error when one attachment cannot be removed.

This commit is contained in:
Thomas Pot
2026-11-13 16:01:54 +01:00
parent eed2959ec1
commit f7bcb72c56
6 changed files with 138 additions and 8 deletions
+16 -3
View File
@@ -191,9 +191,22 @@ class IrLogging(models.Model):
if not attachment_ids:
return 0
self.env['ir.attachment'].sudo().browse(attachment_ids).unlink()
_logger.info('Deleted %s unneeded filestore attachments', len(attachment_ids))
return len(attachment_ids)
deleted_count = 0
attachments = self.env['ir.attachment'].sudo()
for attachment_id in attachment_ids:
try:
with self.env.cr.savepoint():
attachments.browse(attachment_id).unlink()
except Exception:
_logger.warning(
'Could not delete unneeded filestore attachment with id %s',
attachment_id,
)
else:
deleted_count += 1
_logger.info('Deleted %s unneeded filestore attachments', deleted_count)
return deleted_count
def set_db_param(self):
## Script to set database expiration date, when enterprise and test env.