From 2506286c43ebba59de8b9e94c3dd9dce5311970c Mon Sep 17 00:00:00 2001 From: Jon Pentland Date: Fri, 21 Oct 2022 14:18:09 +0100 Subject: [PATCH] Create custom __getattribute__ method to return timezone aware dates from older Comment objects --- plone/app/discussion/comment.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plone/app/discussion/comment.py b/plone/app/discussion/comment.py index 3a02628..62d7811 100644 --- a/plone/app/discussion/comment.py +++ b/plone/app/discussion/comment.py @@ -135,6 +135,17 @@ class Comment( user.getId(): ["Owner"], } + def __getattribute__(self, attr): + # In older versions of the add-on dates were set timezone naive. + # In tz aware versions, the value is stored as self._creation_date + if attr in ["creation_date", "modification_date"]: + old_date = super(Comment, self).__getattribute__(attr) + if old_date.tzinfo is None: + # Naive dates were always stored utc + return old_date.astimezone(timezone.utc) + return old_date + return super(Comment, self).__getattribute__(attr) + @property def __name__(self): return self.comment_id and str(self.comment_id) or None