From e2bd3e328aa0a4e2a438a3b0e9f3fc3fa5601b62 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Wed, 19 Jun 2019 14:19:01 +0000 Subject: [PATCH] [IMP] odoo: remove LazyCursor Was specifically created for decimal.precision at f0646cb51b236a3afd5 Should no longer be needed --- addons/stock/tests/test_move2.py | 12 ----------- odoo/fields.py | 1 - odoo/sql_db.py | 34 -------------------------------- odoo/tools/profiler.py | 2 +- 4 files changed, 1 insertion(+), 48 deletions(-) diff --git a/addons/stock/tests/test_move2.py b/addons/stock/tests/test_move2.py index 53246be2705..635d1b6c121 100644 --- a/addons/stock/tests/test_move2.py +++ b/addons/stock/tests/test_move2.py @@ -1814,18 +1814,9 @@ class TestSinglePicking(TestStockCommon): class TestStockUOM(TestStockCommon): def setUp(self): super(TestStockUOM, self).setUp() - self.setUpCache() - - def setUpCache(self): dp = self.env.ref('product.decimal_product_uom') dp.digits = 7 - # Trick: invoke the method 'precision_get' with the current environment. - # This fills in the cache of the method with the right value. If we - # don't do that, the registry will access the corresponding precision - # with a new cursor (LazyCursor), and get a different value! - self.assertEqual(dp.precision_get(dp.name), 7) - def test_pickings_transfer_with_different_uom_and_back_orders(self): """ Picking transfer with diffrent unit of meassure. """ # weight category @@ -1852,9 +1843,6 @@ class TestStockUOM(TestStockCommon): 'tracking': 'lot', }) - # creating a variant invalidates the cache - self.setUpCache() - picking_in = self.env['stock.picking'].create({ 'partner_id': self.partner_delta_id, 'picking_type_id': self.picking_type_in, diff --git a/odoo/fields.py b/odoo/fields.py index 8c5eee7682f..c95cb00eb85 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -22,7 +22,6 @@ except ImportError: import psycopg2 -from .sql_db import LazyCursor from .tools import float_repr, float_round, frozendict, html_sanitize, human_size, pg_varchar, \ ustr, OrderedSet, pycompat, sql, date_utils, unique, IterableGenerator from .tools import DEFAULT_SERVER_DATE_FORMAT as DATE_FORMAT diff --git a/odoo/sql_db.py b/odoo/sql_db.py index a21890f69f5..debc9f48c42 100644 --- a/odoo/sql_db.py +++ b/odoo/sql_db.py @@ -483,40 +483,6 @@ class TestCursor(object): return value -class LazyCursor(object): - """ A proxy object to a cursor. The cursor itself is allocated only if it is - needed. This class is useful for cached methods, that use the cursor - only in the case of a cache miss. - """ - def __init__(self, dbname=None): - self._dbname = dbname - self._cursor = None - self._depth = 0 - - @property - def dbname(self): - return self._dbname or threading.currentThread().dbname - - def __getattr__(self, name): - cr = self._cursor - if cr is None: - from odoo import registry - cr = self._cursor = registry(self.dbname).cursor() - for _ in range(self._depth): - cr.__enter__() - return getattr(cr, name) - - def __enter__(self): - self._depth += 1 - if self._cursor is not None: - self._cursor.__enter__() - return self - - def __exit__(self, exc_type, exc_value, traceback): - self._depth -= 1 - if self._cursor is not None: - self._cursor.__exit__(exc_type, exc_value, traceback) - class PsycoConnection(psycopg2.extensions.connection): pass diff --git a/odoo/tools/profiler.py b/odoo/tools/profiler.py index dce9f98fb44..0904faf3c1b 100644 --- a/odoo/tools/profiler.py +++ b/odoo/tools/profiler.py @@ -35,7 +35,7 @@ class _LogTracer(object): in_self = frame.f_locals['self'] - if isinstance(in_self, (odoo.sql_db.Cursor, odoo.sql_db.TestCursor, odoo.sql_db.LazyCursor)): + if isinstance(in_self, (odoo.sql_db.Cursor, odoo.sql_db.TestCursor)): return self.tracer model = getattr(in_self, '_name', None)