From 2df240ded02bf5aafee40c6f78b075e6f05fda89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Fri, 2 Oct 2015 14:52:50 +0200 Subject: [PATCH] [FIX] bus : notification should be committed before awake longtpolling thread If calling more than once `sendmany` (or `sendone`) on the same http request, the `NOTIFY imbus` will tell pertinent polling thread to fetch their notifications in the bus table, which will not contain the new notifications, since they are not yet committed. For some reason, this doesn't happen when calling only once `sendmany`. Committing the notifications breaks the tests since no rollback is possible. So, `self._cr.commit()` should not be called in a test environement. In this case, we cannot use `isinstance(self._cr, TestCursor)` since TestCursor is only avaiblable for http request in test mode. Here the cursor is a normal cursor, and to determine if we are in test mode, there is no other option than checking the config of the odoo server. --- addons/bus/models/bus.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/bus/models/bus.py b/addons/bus/models/bus.py index 82d8131061d..9e7a37994eb 100644 --- a/addons/bus/models/bus.py +++ b/addons/bus/models/bus.py @@ -55,6 +55,13 @@ class ImBus(models.Model): if random.random() < 0.01: self.gc() if channels: + # The notifications must be commited in database because when calling `NOTIFY imbus`, some pertinent + # threads will be awakened and will fetch the notification in the bus table, but since the transaction + # is not commited, there will be nothing to fetch, the longpolling will return empty list of notification. + # For some reason, this happen when `sendmany` is called more than once on the same request. + # `self._cr.commit()` is prevented in a test environement, to allow test rollback. + if not openerp.tools.config['test_enable']: + self._cr.commit() with openerp.sql_db.db_connect('postgres').cursor() as cr2: cr2.execute("notify imbus, %s", (json_dump(list(channels)),))