From 11906b776e1fc459d1b5eb9e4dc036e7627665d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Dec 2022 14:46:28 +0000 Subject: [PATCH] [FIX] mail: remove microseconds when parsing vague datetime Mail holds an helper function to convert datetime from a char input into a datetime value. It is used notably when having to store a datetime value (e.g. on a mail_mail) from a string generated by templates with expression like ``{{ datetime.datetime.now() + datetime.timedelta(days=2)}}``. In this commit we explicitly remove microseconds, as otherwise we end up with something that the web client cannot parse, not speaking of even going into server side storage with this value not matching the expected format. Task-2710804 (Mail: Clean MailThread Posting API) Part-of: odoo/odoo#99482 --- addons/mail/models/mail_mail.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index 02f8edbb129..533821fffc8 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -309,6 +309,7 @@ class MailMail(models.Model): except (ValueError, TypeError): parsed_datetime = False if parsed_datetime: + parsed_datetime = parsed_datetime.replace(microsecond=0) if not parsed_datetime.tzinfo: parsed_datetime = pytz.utc.localize(parsed_datetime) else: