Page MenuHomekolab.org

Wallace expunge old events in resources fails due to datetime comparison TypeError
Closed, ResolvedPublic

Description

I am observing errors in pykolab.log file:

2016-11-16 09:02:00,558 pykolab.wallace ERROR Expunge resource calendar for cn=Besprechungsraum Forest 0-56-R2,ou=Resources,dc=genua,dc=de (shared/Resources/<mailbox>) failed: TypeError("can't compare datetime.datetime to datetime.date",)

This is because parsing event wallace gets event end time as a date, not as datetime instance.
Of course, the first question is how come there are events which have end date without time, but I suggest to add yet another try and except clause to wallace code:

--- /usr/lib/python2.7/dist-packages/wallace/module_resources.py.orig   2016-07-08 15:05:54.887180000 +0200
+++ /usr/lib/python2.7/dist-packages/wallace/module_resources.py        2016-11-16 09:38:28.341581635 +0100
@@ -491,11 +507,16 @@ def expunge_resource_calendar(mailbox):
                 if dt_end is None:
                     # skip if recurring forever
                     continue
+           
+           try:
+                if dt_end and dt_end < expire_date:
+                    age = now - dt_end
+                    log.debug(_("Flag event %s from message %s/%s as deleted (age = %d days)") % (event.uid, mailbox, num, age.days), level=8)
+                    imap.imap.m.store(num, '+FLAGS', '\\Deleted')
+           except TypeError:
+                log.error(_("Event: %s in mailbox %s, Event end: %s") % (num, mailbox, dt_end))
+               continue
 
-            if dt_end and dt_end < expire_date:
-                age = now - dt_end
-                log.debug(_("Flag event %s from message %s/%s as deleted (age = %d days)") % (event.uid, mailbox, num, age.days), level=8)
-                imap.imap.m.store(num, '+FLAGS', '\\Deleted')

It is also possible to try to convert datetime.date to datetime.datetime before checking if the end of event is more than 100 days ago.

dpkg -l pykolab wallace

ii pykolab 0.7.30-0~kolab1 all Kolab Groupware daemon and utilities
ii wallace 0.7.30-0~kolab1 all Kolab Content-Filter

Event Timeline

adomaitis added a project: PyKolab.

I think a date is possible here if the event is full-day recurring event. In such a case to_dt() is not used on the event last occurence date in https://git.kolab.org/diffusion/P/browse/master/wallace/module_resources.py;71df0cc7b4fc8373e6d84db8e8c01e56ca99ad25$506

Could you see if changing:

dt_end = event.get_last_occurrence()

to

dt_end = to_dt(event.get_last_occurrence())

fixes the issue?

Aye, looks like so - don't see any TypeErrors with patch you proposed.