From 80b55b1f00d8f94138bdee8f267ee6cfde3ae88b Mon Sep 17 00:00:00 2001 From: sebalix Date: Mon, 9 Feb 2015 14:36:07 +0100 Subject: [PATCH] [FIX] Module 'auditlog' - When updating a resource, filter IDs on 2many fields to prevent a 'name_get()' call on potential deleted resources --- auditlog/models/rule.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 8a88299b7..9cd9007c7 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -351,8 +351,18 @@ class auditlog_rule(models.Model): } # for *2many fields, log the name_get if field['relation'] and '2many' in field['ttype']: - old_value_text = self.env[field['relation']].browse( - vals['old_value']).name_get() + # Filter IDs to prevent a 'name_get()' call on deleted resources + existing_ids = self.env[field['relation']]._search( + [('id', 'in', vals['old_value'])]) + old_value_text = [] + if existing_ids: + existing_values = self.env[field['relation']].browse( + existing_ids).name_get() + old_value_text.extend(existing_values) + # Deleted resources will have a 'DELETED' text representation + deleted_ids = set(vals['old_value']) - set(existing_ids) + for deleted_id in deleted_ids: + old_value_text.append((deleted_id, 'DELETED')) vals['old_value_text'] = old_value_text new_value_text = self.env[field['relation']].browse( vals['new_value']).name_get()