Files
odoo_source/odoo/addons/test_new_api/tests/test_attributes.py
T
Raphael Collet ea3e39506a [IMP] models: use slots for BaseModel
This restricts the attributes of a BaseModel instance to `env`, `_ids`
and `_prefetch_ids`.  This way, one can only assign fields on a record;
other assignments are programming errors.

This also reduces the memory footprint of records from 168 to 64 bytes
(-62%), and makes their instanciation faster.

closes odoo/odoo#51075

Related: odoo/enterprise#10529
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-05-18 09:51:43 +00:00

13 lines
330 B
Python

# -*- coding: utf-8 -*-
from odoo.tests import common
class TestAttributes(common.TransactionCase):
def test_we_cannot_add_attributes(self):
Model = self.env['test_new_api.category']
instance = Model.create({'name': 'Foo'})
with self.assertRaises(AttributeError):
instance.unknown = 42