This branch is the combination of several optimizations in the ORM: * store field values once in the cache: the cache reflects more faithfully the database, only fields that explicitly depend on the context have an extra indirection in the cache; * delay recomputations by default: use method `recompute` to explicitly flush out pending recomputations; * delay updates in method `write`: updates are stored in a data structure that can be flushed efficiently to the database with method `flush` (which also flush out recomputations); * make method `modified` take advantage of inverse fields to inverse dependencies; * filter records by evaluating a domain on records in Python; * a computed field with `readonly=False` behaves like a normal field with an onchange method; * computed fields are computed in superuser mode by default. Work done by Toufik Ben Jaa, Raphael Collet, Denis Ledoux and Fabien Pinckaers. closes odoo/odoo#35659 Signed-off-by: Denis Ledoux <beledouxdenis@users.noreply.github.com>
118 lines
3.5 KiB
Python
118 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
|
|
import odoo
|
|
from odoo.sql_db import TestCursor
|
|
from odoo.tests import common
|
|
from odoo.tests.common import BaseCase
|
|
from odoo.tools.misc import mute_logger
|
|
|
|
ADMIN_USER_ID = common.ADMIN_USER_ID
|
|
|
|
def registry():
|
|
return odoo.registry(common.get_db_name())
|
|
|
|
|
|
class TestExecute(BaseCase):
|
|
""" Try cr.execute with wrong parameters """
|
|
|
|
@mute_logger('odoo.sql_db')
|
|
def test_execute_bad_params(self):
|
|
"""
|
|
Try to use iterable but non-list or int params in query parameters.
|
|
"""
|
|
with registry().cursor() as cr:
|
|
with self.assertRaises(ValueError):
|
|
cr.execute("SELECT id FROM res_users WHERE login=%s", 'admin')
|
|
with self.assertRaises(ValueError):
|
|
cr.execute("SELECT id FROM res_users WHERE id=%s", 1)
|
|
with self.assertRaises(ValueError):
|
|
cr.execute("SELECT id FROM res_users WHERE id=%s", '1')
|
|
|
|
|
|
class TestTestCursor(common.TransactionCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(TestTestCursor, cls).setUpClass()
|
|
r = registry()
|
|
r.enter_test_mode(r.cursor())
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
r = registry()
|
|
r.test_cr.close()
|
|
r.leave_test_mode()
|
|
super(TestTestCursor, cls).tearDownClass()
|
|
|
|
def setUp(self):
|
|
super(TestTestCursor, self).setUp()
|
|
self.record = self.env['res.partner'].create({'name': 'Foo'})
|
|
|
|
def write(self, record, value):
|
|
record.ref = value
|
|
|
|
def flush(self, record):
|
|
record.flush(['ref'])
|
|
|
|
def check(self, record, value):
|
|
self.assertEqual(record.read(['ref'])[0]['ref'], value)
|
|
|
|
def test_single_cursor(self):
|
|
""" Check the behavior of a single test cursor. """
|
|
self.assertIsInstance(self.cr, TestCursor)
|
|
self.write(self.record, 'A')
|
|
self.cr.commit()
|
|
|
|
self.write(self.record, 'B')
|
|
self.cr.rollback()
|
|
self.check(self.record, 'A')
|
|
|
|
self.write(self.record, 'C')
|
|
self.cr.rollback()
|
|
self.check(self.record, 'A')
|
|
|
|
def test_sub_commit(self):
|
|
""" Check the behavior of a subcursor that commits. """
|
|
self.assertIsInstance(self.cr, TestCursor)
|
|
self.write(self.record, 'A')
|
|
self.cr.commit()
|
|
|
|
self.write(self.record, 'B')
|
|
self.flush(self.record)
|
|
|
|
# check behavior of a "sub-cursor" that commits
|
|
with self.registry.cursor() as cr:
|
|
self.assertIsInstance(cr, TestCursor)
|
|
record = self.record.with_env(self.env(cr=cr))
|
|
self.check(record, 'B')
|
|
self.write(record, 'C')
|
|
|
|
self.check(self.record, 'C')
|
|
|
|
self.cr.rollback()
|
|
self.check(self.record, 'A')
|
|
|
|
def test_sub_rollback(self):
|
|
""" Check the behavior of a subcursor that rollbacks. """
|
|
self.assertIsInstance(self.cr, TestCursor)
|
|
self.write(self.record, 'A')
|
|
self.cr.commit()
|
|
|
|
self.write(self.record, 'B')
|
|
self.flush(self.record)
|
|
|
|
# check behavior of a "sub-cursor" that rollbacks
|
|
with self.assertRaises(ValueError):
|
|
with self.registry.cursor() as cr:
|
|
self.assertIsInstance(cr, TestCursor)
|
|
record = self.record.with_env(self.env(cr=cr))
|
|
self.check(record, 'B')
|
|
self.write(record, 'C')
|
|
raise ValueError(42)
|
|
|
|
self.check(self.record, 'B')
|
|
|
|
self.cr.rollback()
|
|
self.check(self.record, 'A')
|