summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2016-01-15 12:28:15 +0100
committerRaphael Collet <rco@openerp.com>2016-01-15 17:04:45 +0100
commit18f3de2f19dcc211b10cc8b9f1cfd5fcdca22a9e (patch)
tree873476d69c6671fa3d2f80637c005c1fbd0b3a2a /addons
parent20cfdc460436529be5aa2b024bc8d5ea5046a294 (diff)
[FIX] bus: delay the postgres notification until the transaction is committed
This is much better than committing the current transaction without notice.
Diffstat (limited to 'addons')
-rw-r--r--addons/bus/models/bus.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/addons/bus/models/bus.py b/addons/bus/models/bus.py
index 6438e0c832e..a54e083ae85 100644
--- a/addons/bus/models/bus.py
+++ b/addons/bus/models/bus.py
@@ -55,15 +55,15 @@ 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)),))
+ # We have to wait until the notifications are commited in database.
+ # When calling `NOTIFY imbus`, some concurrent threads will be
+ # awakened and will fetch the notification in the bus table. If the
+ # transaction is not commited yet, there will be nothing to fetch,
+ # and the longpolling will return no notification.
+ def notify():
+ with openerp.sql_db.db_connect('postgres').cursor() as cr:
+ cr.execute("notify imbus, %s", (json_dump(list(channels)),))
+ self._cr.after('commit', notify)
@api.model
def sendone(self, channel, message):