diff --git a/addons/bus/models/bus.py b/addons/bus/models/bus.py index 1e62ad6eb48..b88a833601b 100644 --- a/addons/bus/models/bus.py +++ b/addons/bus/models/bus.py @@ -59,10 +59,10 @@ class ImBus(models.Model): # 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. + @self.env.cr.postcommit.add def notify(): with odoo.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): diff --git a/addons/google_calendar/models/google_sync.py b/addons/google_calendar/models/google_sync.py index 9957bdad6cc..f29302ce1f7 100644 --- a/addons/google_calendar/models/google_sync.py +++ b/addons/google_calendar/models/google_sync.py @@ -30,6 +30,8 @@ def after_commit(func): dbname = self.env.cr.dbname context = self.env.context uid = self.env.uid + + @self.env.cr.postcommit.add def called_after(): db_registry = registry(dbname) with api.Environment.manage(), db_registry.cursor() as cr: @@ -39,7 +41,7 @@ def after_commit(func): except Exception as e: _logger.warning("Could not sync record now: %s" % self) _logger.exception(e) - self.env.cr.after('commit', called_after) + return wrapped @contextmanager diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 77b84a7c5f2..8cb3695d1db 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -2281,12 +2281,13 @@ class MailThread(models.AbstractModel): email_ids = emails.ids dbname = self.env.cr.dbname _context = self._context + + @self.env.cr.postcommit.add def send_notifications(): db_registry = registry(dbname) with api.Environment.manage(), db_registry.cursor() as cr: env = api.Environment(cr, SUPERUSER_ID, _context) env['mail.mail'].browse(email_ids).send() - self._cr.after('commit', send_notifications) else: emails.send() diff --git a/addons/microsoft_calendar/models/microsoft_sync.py b/addons/microsoft_calendar/models/microsoft_sync.py index 312904779ec..888fe09eff0 100644 --- a/addons/microsoft_calendar/models/microsoft_sync.py +++ b/addons/microsoft_calendar/models/microsoft_sync.py @@ -32,6 +32,8 @@ def after_commit(func): dbname = self.env.cr.dbname context = self.env.context uid = self.env.uid + + @self.env.cr.postcommit.add def called_after(): db_registry = registry(dbname) with api.Environment.manage(), db_registry.cursor() as cr: @@ -41,7 +43,7 @@ def after_commit(func): except Exception as e: _logger.warning("Could not sync record now: %s" % self) _logger.exception(e) - self.env.cr.after('commit', called_after) + return wrapped @contextmanager diff --git a/addons/website/__init__.py b/addons/website/__init__.py index 748058ff042..c4161c8635e 100644 --- a/addons/website/__init__.py +++ b/addons/website/__init__.py @@ -19,7 +19,8 @@ def uninstall_hook(cr, registry): ('name', '=', 'website_id'), ('model', '=', 'res.config.settings'), ]).unlink() - cr.after('commit', partial(rem_website_id_null, cr.dbname)) + + cr.postcommit.add(partial(rem_website_id_null, cr.dbname)) def post_init_hook(cr, registry): diff --git a/odoo/sql_db.py b/odoo/sql_db.py index e8426691cd1..ce49fb6a60a 100644 --- a/odoo/sql_db.py +++ b/odoo/sql_db.py @@ -14,6 +14,7 @@ import itertools import logging import time import uuid +import warnings from decorator import decorator import psycopg2 @@ -420,6 +421,10 @@ class Cursor(BaseCursor): back or committed independently. You may consider the use of a dedicated temporary cursor to do some database operation. """ + warnings.warn( + "Cursor.after() is deprecated, use Cursor.postcommit.add() instead.", + DeprecationWarning, + ) if event == 'commit': self.postcommit.add(func) elif event == 'rollback':