diff --git a/odoo/addons/test_new_api/tests/test_new_fields.py b/odoo/addons/test_new_api/tests/test_new_fields.py index e351d9ef19d..4f14974ec44 100644 --- a/odoo/addons/test_new_api/tests/test_new_fields.py +++ b/odoo/addons/test_new_api/tests/test_new_fields.py @@ -3260,6 +3260,14 @@ class TestHtmlField(common.TransactionCase): self.assertEqual(record.comment5, '', "should be sanitized (not in groups)") + # extra test with new record having 'record' as origin + new_record = record.new(origin=record) + new_record.with_user(bypass_user).comment5 + + # this was causing an infinite recursion (see explanation in fields.py) + new_record.invalidate_recordset() + new_record.with_user(internal_user).comment5 + class TestMagicFields(common.TransactionCase): diff --git a/odoo/fields.py b/odoo/fields.py index 0528555ec27..72ae89920cb 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -2002,7 +2002,11 @@ class Html(_String): if record.user_has_groups('base.group_sanitize_override'): return value - original_value = record[self.name] + # This may cause an infinite recursion when accessing the field on a + # new record. Indeed, if record has no value in cache, we default + # on the field's value on record._origin and convert it to the + # cache format, which ends up here, accessing the field on record! + original_value = record[self.name] if record.id else None if original_value: # Note that sanitize also normalize original_value_sanitized = html_sanitize(original_value, **sanitize_vals)