From 7cfd5eba46376597938ada7a8e738864306017f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 21 Apr 2026 12:28:49 +0200 Subject: [PATCH] Process exception of RPC calls for chat Closes #14790 (grafted from e47e55822e32ef31aee016882fce0cb0a530e6eb) --HG-- branch : 8.0 --- tryton/tryton/chat.py | 79 ++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/tryton/tryton/chat.py b/tryton/tryton/chat.py index 23fa43db40..67ca947942 100644 --- a/tryton/tryton/chat.py +++ b/tryton/tryton/chat.py @@ -6,7 +6,7 @@ from gi.repository import Gdk, Gio, GLib, GObject, Gtk from tryton import common, rpc from tryton.bus import Bus -from tryton.common import sur +from tryton.common import RPCException, RPCExecute, sur _ = gettext.gettext @@ -66,13 +66,18 @@ class Chat: Bus.unregister(f"chat:{self.record}", self.notify) def send_message(self, message, internal): - rpc.execute( - 'model', 'ir.chat.channel', 'post', self.record, message, - 'internal' if internal else 'public', rpc.CONTEXT) + try: + RPCExecute( + 'model', 'ir.chat.channel', 'post', self.record, message, + 'internal' if internal else 'public') + except RPCException: + pass def get_messages(self): - return rpc.execute( - 'model', 'ir.chat.channel', 'get', self.record, rpc.CONTEXT) + try: + return RPCExecute('model', 'ir.chat.channel', 'get', self.record) + except RPCException: + return [] def notify(self, message): self.refresh() @@ -138,9 +143,12 @@ class Chat: method = 'unsubscribe' elif follower['type'] == 'email': method = 'unsubscribe_email' - rpc.execute( - 'model', 'ir.chat.channel', method, - self.record, follower['key'], rpc.CONTEXT) + try: + RPCExecute( + 'model', 'ir.chat.channel', method, + self.record, follower['key']) + except RPCException: + pass subscribe_popover.popdown() return do_unsubscribe @@ -181,14 +189,15 @@ class Chat: def toggle_subscribe(button): nonlocal subscribed - if subscribed: - rpc.execute( - 'model', 'ir.chat.channel', 'unsubscribe', self.record, - rpc.CONTEXT) - else: - rpc.execute( - 'model', 'ir.chat.channel', 'subscribe', self.record, - rpc.CONTEXT) + try: + if subscribed: + RPCExecute( + 'model', 'ir.chat.channel', 'unsubscribe', self.record) + else: + RPCExecute( + 'model', 'ir.chat.channel', 'subscribe', self.record) + except RPCException: + return subscribed = not subscribed set_subscribe_state() if subscribed: @@ -246,25 +255,33 @@ class Chat: return widget def _get_followers(self): - return rpc.execute( - 'model', 'ir.chat.channel', 'get_followers', self.record, - rpc.CONTEXT) + try: + return RPCExecute( + 'model', 'ir.chat.channel', 'get_followers', self.record) + except RPCException: + return [] def _search_followers(self, text): - followers = rpc.execute( - 'model', 'ir.chat.channel', 'search_followers', - str(self.record), text, rpc.CONTEXT) + try: + followers = RPCExecute( + 'model', 'ir.chat.channel', 'search_followers', + str(self.record), text) + except RPCException: + followers = [] return filter(lambda f: not _follower_self(f), followers) def _add_follower(self, follower): - if follower['type'] == 'user': - rpc.execute( - 'model', 'ir.chat.channel', 'subscribe', - self.record, follower['key'], rpc.CONTEXT) - elif follower['type'] == 'email': - rpc.execute( - 'model', 'ir.chat.channel', 'subscribe_email', - self.record, follower['key'], rpc.CONTEXT) + try: + if follower['type'] == 'user': + RPCExecute( + 'model', 'ir.chat.channel', 'subscribe', + self.record, follower['key']) + elif follower['type'] == 'email': + RPCExecute( + 'model', 'ir.chat.channel', 'subscribe_email', + self.record, follower['key']) + except RPCException: + pass def __build_follower_entry(self): tooltips = common.Tooltips()