diff options
| author | Raphael Collet <rco@odoo.com> | 2021-01-19 17:14:08 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2021-01-20 09:03:18 +0000 |
| commit | a4d7e01e2a27e90060ffd19dffbad3cead5d608b (patch) | |
| tree | 62c23e8a73db2251d9739b95c6f660c12801dc5d | |
| parent | 3655efc990d4792453304938d555122f4f5d3c88 (diff) | |
[FIX] core: exists() with string ids
The call model.browse('xxx').exists() should not return the record.
Instead, it should fail as the string 'xxx' is not a valid ID.
closes odoo/odoo#64779
X-original-commit: 824a6515a528cd2b682c3d3504c0d27ed9427cdb
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
| -rw-r--r-- | odoo/addons/base/tests/test_orm.py | 12 | ||||
| -rw-r--r-- | odoo/models.py | 2 |
2 files changed, 13 insertions, 1 deletions
diff --git a/odoo/addons/base/tests/test_orm.py b/odoo/addons/base/tests/test_orm.py index 285e4b67290..4ccfa6a0dd3 100644 --- a/odoo/addons/base/tests/test_orm.py +++ b/odoo/addons/base/tests/test_orm.py @@ -3,6 +3,8 @@ from collections import defaultdict +import psycopg2 + from odoo.exceptions import AccessError, MissingError from odoo.tests.common import TransactionCase from odoo.tools import mute_logger @@ -136,6 +138,7 @@ class TestORM(TransactionCase): self.assertEqual(len(found), 1) self.assertTrue(field in list(found[0]) for field in ['id', 'name', 'display_name', 'email']) + @mute_logger('odoo.sql_db') def test_exists(self): partner = self.env['res.partner'] @@ -144,10 +147,19 @@ class TestORM(TransactionCase): self.assertTrue(recs) self.assertEqual(recs.exists(), recs) + # check that new records exist by convention + recs = partner.new({}) + self.assertTrue(recs.exists()) + # check that there is no record with id 0 recs = partner.browse([0]) self.assertFalse(recs.exists()) + # check that there is no record with string id + recs = partner.browse('xxx') + with self.assertRaises(psycopg2.DataError): + recs.exists() + def test_groupby_date(self): partners_data = dict( A='2012-11-19', diff --git a/odoo/models.py b/odoo/models.py index 44ab1498350..1f4c5ba0e2b 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -4673,7 +4673,7 @@ Fields: """ ids, new_ids = [], [] for i in self._ids: - (ids if isinstance(i, int) else new_ids).append(i) + (new_ids if isinstance(i, NewId) else ids).append(i) if not ids: return self query = """SELECT id FROM "%s" WHERE id IN %%s""" % self._table |
