collective / icalendar

icalendar parser library for Python
https://icalendar.readthedocs.io
Other
1k stars 172 forks source link

EXDATE info type in prop.Event is inconsistent (can be list of vDDDLists or just one object instance) #224

Open mlorant opened 7 years ago

mlorant commented 7 years ago

I think a print trace of the problem is worth 1,000 words:

# Case 1
BEGIN:VEVENT
SUMMARY:Recurrence with 2 deleted days
DTSTART;TZID=Europe/Paris:20170502T100000
DTEND;TZID=Europe/Paris:20170502T110000
DTSTAMP:20170504T085344Z
UID:uid-0
EXDATE;TZID=Europe/Paris:20170523T100000
EXDATE;TZID=Europe/Paris:20170516T100000
RRULE:FREQ=WEEKLY;BYDAY=TU
STATUS:CONFIRMED
END:VEVENT

[<icalendar.prop.vDDDLists object at 0x7fe2ed87ef28>, <icalendar.prop.vDDDLists object at 0x7fe2ed87ebe0>]
type(event['EXDATE']) =  <class 'list'>

# Case 2
BEGIN:VEVENT
SUMMARY:Recurrence with one deleted day 
DTSTART;TZID=Europe/Paris:20170502T023000
DTEND;TZID=Europe/Paris:20170502T033000
DTSTAMP:20170504T085344Z
UID:uid-1
EXDATE;TZID=Europe/Paris:20170509T023000
RRULE:FREQ=WEEKLY;BYDAY=TU
STATUS:CONFIRMED
END:VEVENT

<icalendar.prop.vDDDLists object at 0x7fe2ed4234e0>
type(event['EXDATE']) =  <class 'icalendar.prop.vDDDLists'>

As you can see, we can't rely on the type of EXDATE, since it can either be a Python list of vDDDLists or just one vDDDLists instance. In my own application, I had to do this workaround to have a generic way of handling:

exdates = event['EXDATE']
if isinstance(event['EXDATE'], icalendar.prop.vDDDLists):
     exdates = [exdates]

Either vDDDLists objects should be merged in a single one (best abstraction API I think), either EXDATE should always return a list of lists. But not both behaviour...

stlaz commented 7 years ago

This will hopefully be resolved with https://github.com/collective/icalendar/pull/192 which should come next major release.

4xel commented 6 years ago

+1

niccokunzmann commented 5 months ago

See also: https://github.com/collective/icalendar/discussions/662