diff --git a/trytond/trytond/cache.py b/trytond/trytond/cache.py index 7d99ba0331..2e71da0be0 100644 --- a/trytond/trytond/cache.py +++ b/trytond/trytond/cache.py @@ -374,8 +374,7 @@ class MemoryCache(BaseCache): database = backend.Database(dbname) conn = database.get_connection() try: - cursor = conn.cursor() - cursor.execute('NOTIFY "%s"' % cls._channel) + database.notify(conn, cls._channel, "") conn.commit() finally: database.put_connection(conn) @@ -396,8 +395,7 @@ class MemoryCache(BaseCache): process_id = cls._local.portable_id payload = f"{REFRESH_POOL_MSG} {process_id}" try: - cursor = conn.cursor() - cursor.execute(f'NOTIFY "{cls._channel}", %s', (payload,)) + database.notify(conn, cls._channel, payload) conn.commit() finally: database.put_connection(conn) diff --git a/trytond/trytond/tests/test_cache.py b/trytond/trytond/tests/test_cache.py index cf20dc147f..b682c3b444 100644 --- a/trytond/trytond/tests/test_cache.py +++ b/trytond/trytond/tests/test_cache.py @@ -8,7 +8,8 @@ from unittest.mock import patch from trytond import backend, config from trytond.cache import ( - LRUDict, LRUDictTransaction, MemoryCache, freeze, unfreeze) + REFRESH_POOL_MSG, LRUDict, LRUDictTransaction, MemoryCache, freeze, + unfreeze) from trytond.tests.test_tryton import ( DB_NAME, USER, TestCase, activate_module, with_transaction) from trytond.transaction import Transaction @@ -264,6 +265,19 @@ class MemoryCacheChannelTestCase(MemoryCacheTestCase): def test_memory_cache_sync(self): super().test_memory_cache_sync() + @with_transaction() + def test_memory_cache_refresh_pool(self): + "Test MemoryCache refresh_pool uses Database.notify" + transaction = Transaction() + with patch( + 'trytond.backend.Database.notify', + side_effect=transaction.database.notify) as notify: + cache.refresh_pool(transaction) + self.assertEqual( + notify.call_args.args[1:], + (cache._channel, + f"{REFRESH_POOL_MSG} {cache._local.portable_id}")) + class LRUDictTestCase(TestCase): "Test LRUDict"