From f0f0e1f09b17cf3c4b156283d44dc2d21d29b8d7 Mon Sep 17 00:00:00 2001 From: SupportSNDC Date: Tue, 18 Nov 2025 16:56:54 +0100 Subject: [PATCH 1/2] [16.0][FIX] mail_activity_done: handle SQL objects in execute wrapper --- mail_activity_done/models/mail_activity.py | 83 +++++++++++++++++----- 1 file changed, 66 insertions(+), 17 deletions(-) diff --git a/mail_activity_done/models/mail_activity.py b/mail_activity_done/models/mail_activity.py index 1d11086f69..7892e49eb4 100644 --- a/mail_activity_done/models/mail_activity.py +++ b/mail_activity_done/models/mail_activity.py @@ -91,17 +91,41 @@ def _read_progress_bar(self, domain, group_by, progress_bar): execute_org = self._cr.execute def execute(query, params=None, log_exceptions=True): + # Convert to string according to query type + if hasattr(query, 'as_string'): + # psycopg2 SQL object + try: + query_str = query.as_string(self._cr._cnx) + except Exception: + query_str = str(query) + elif isinstance(query, str): + query_str = query + else: + # Composite SQL object - leave as is if no pattern + query_str = str(query) if hasattr(query, '__str__') else query + original_where = "WHERE res_model = '{}'".format(self._name) - replace_where = ( - "WHERE res_model = '{}' AND mail_activity.done = FALSE".format( - self._name + + # Only modify if the pattern exists in the query + if isinstance(query_str, str) and original_where in query_str: + replace_where = ( + "WHERE res_model = '{}' AND mail_activity.done = FALSE".format( + self._name + ) + ) + modified_query = query_str.replace(original_where, replace_where) + return execute_org( + modified_query, + params=params, + log_exceptions=log_exceptions, + ) + else: + # Pass the original query without modification + return execute_org( + query, + params=params, + log_exceptions=log_exceptions, ) - ) - return execute_org( - query.replace(original_where, replace_where), - params=params, - log_exceptions=log_exceptions, - ) self._cr.execute = execute try: @@ -113,18 +137,43 @@ def _search_activity_state(self, operator, value): execute_org = self._cr.execute def execute(query, params=None, log_exceptions=True): - return execute_org( - query.replace( - "WHERE mail_activity.res_model = %(res_model_table)s", + # Convert to string according to query type + if hasattr(query, 'as_string'): + # psycopg2 SQL object + try: + query_str = query.as_string(self._cr._cnx) + except Exception: + query_str = str(query) + elif isinstance(query, str): + query_str = query + else: + # Composite SQL object - leave as is if no pattern + query_str = str(query) if hasattr(query, '__str__') else query + + pattern = "WHERE mail_activity.res_model = %(res_model_table)s" + + # Only modify if the pattern exists in the query + if isinstance(query_str, str) and pattern in query_str: + modified_query = query_str.replace( + pattern, "WHERE mail_activity.res_model = %(res_model_table)s AND " "mail_activity.done = FALSE", - ), - params=params, - log_exceptions=log_exceptions, - ) + ) + return execute_org( + modified_query, + params=params, + log_exceptions=log_exceptions, + ) + else: + # Pass the original query without modification + return execute_org( + query, + params=params, + log_exceptions=log_exceptions, + ) self._cr.execute = execute try: return super()._search_activity_state(operator, value) finally: - self._cr.execute = execute_org + self._cr.execute = execute_org \ No newline at end of file From 6d6ef20b87d9e8d2409fe80d28dc244dd8b56385 Mon Sep 17 00:00:00 2001 From: SupportSNDC Date: Wed, 19 Nov 2025 11:47:58 +0100 Subject: [PATCH 2/2] fix: apply black formatting and fix line endings --- mail_activity_done/models/mail_activity.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mail_activity_done/models/mail_activity.py b/mail_activity_done/models/mail_activity.py index 7892e49eb4..f9b03b1ac3 100644 --- a/mail_activity_done/models/mail_activity.py +++ b/mail_activity_done/models/mail_activity.py @@ -92,7 +92,7 @@ def _read_progress_bar(self, domain, group_by, progress_bar): def execute(query, params=None, log_exceptions=True): # Convert to string according to query type - if hasattr(query, 'as_string'): + if hasattr(query, "as_string"): # psycopg2 SQL object try: query_str = query.as_string(self._cr._cnx) @@ -102,10 +102,10 @@ def execute(query, params=None, log_exceptions=True): query_str = query else: # Composite SQL object - leave as is if no pattern - query_str = str(query) if hasattr(query, '__str__') else query - + query_str = str(query) if hasattr(query, "__str__") else query + original_where = "WHERE res_model = '{}'".format(self._name) - + # Only modify if the pattern exists in the query if isinstance(query_str, str) and original_where in query_str: replace_where = ( @@ -138,7 +138,7 @@ def _search_activity_state(self, operator, value): def execute(query, params=None, log_exceptions=True): # Convert to string according to query type - if hasattr(query, 'as_string'): + if hasattr(query, "as_string"): # psycopg2 SQL object try: query_str = query.as_string(self._cr._cnx) @@ -148,10 +148,10 @@ def execute(query, params=None, log_exceptions=True): query_str = query else: # Composite SQL object - leave as is if no pattern - query_str = str(query) if hasattr(query, '__str__') else query - + query_str = str(query) if hasattr(query, "__str__") else query + pattern = "WHERE mail_activity.res_model = %(res_model_table)s" - + # Only modify if the pattern exists in the query if isinstance(query_str, str) and pattern in query_str: modified_query = query_str.replace( @@ -176,4 +176,4 @@ def execute(query, params=None, log_exceptions=True): try: return super()._search_activity_state(operator, value) finally: - self._cr.execute = execute_org \ No newline at end of file + self._cr.execute = execute_org