summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odoo/addons/test_access_rights/tests/test_ir_rules.py6
-rw-r--r--odoo/models.py3
2 files changed, 9 insertions, 0 deletions
diff --git a/odoo/addons/test_access_rights/tests/test_ir_rules.py b/odoo/addons/test_access_rights/tests/test_ir_rules.py
index 6724bdbf1e4..9cb2f3ebda2 100644
--- a/odoo/addons/test_access_rights/tests/test_ir_rules.py
+++ b/odoo/addons/test_access_rights/tests/test_ir_rules.py
@@ -76,3 +76,9 @@ class TestRules(TransactionCase):
container_user.write({'some_ids': [(5,)]})
self.assertItemsEqual(container_user.some_ids.ids, [])
self.assertItemsEqual(container_admin.some_ids.ids, [self.id2])
+
+ def test_access_rule_performance(self):
+ env = self.env(user=self.browse_ref('base.public_user'))
+ Model = env['test_access_right.some_obj']
+ with self.assertQueryCount(0):
+ Model._filter_access_rules('read')
diff --git a/odoo/models.py b/odoo/models.py
index b1cb70599c9..7178f27f24c 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -3102,6 +3102,9 @@ Fields:
if self._uid == SUPERUSER_ID:
return self
+ if not self._ids:
+ return self
+
if self.is_transient():
# Only one single implicit access rule for transient models: owner only!
# This is ok to hardcode because we assert that TransientModels always