allenporter/ical

Validation error: DTSTART and UNTIL must be the same value type

tmm1 opened this issue · 2 comments

tmm1 commented

Describe the bug

Parsing google calendar output fails

To Reproduce

>>> import requests
>>> from ical.calendar_stream import IcsCalendarStream
>>> url = 'https://calendar.google.com/calendar/ical/mg877fp19824mj30g497frm74o%40group.calendar.google.com/public/basic.ics'
>>> cal = IcsCalendarStream.calendar_from_ics(requests.get(url).text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.11/site-packages/ical/calendar_stream.py", line 74, in calendar_from_ics
    stream = cls.from_ics(content)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/ical/calendar_stream.py", line 61, in from_ics
    return cls.parse_obj(result)
           ^^^^^^^^^^^^^^^^^^^^^
  File "pydantic/main.py", line 526, in pydantic.main.BaseModel.parse_obj
  File "pydantic/main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for IcsCalendarStream
vcalendar -> 0 -> vevent -> 2991 -> __root__
  DTSTART and UNTIL must be the same value type (type=value_error)

Expected behavior

no failure

Thank you for the detailed bug report. I believe the particular event is:

BEGIN:VEVENT
DTSTART;VALUE=DATE:20110806
DTEND;VALUE=DATE:20110807
RRULE:FREQ=WEEKLY;UNTIL=20110812T070000Z;BYDAY=SA
...
END:VEVENT

The specific validation rule this is implementing comes from https://www.rfc-editor.org/rfc/rfc5545#section-3.3.10

The UNTIL rule part defines a DATE or DATE-TIME value that bounds
the recurrence rule in an inclusive manner.  ... 
... The value of the UNTIL rule part MUST have the same
value type as the "DTSTART" property.  Furthermore, if the
"DTSTART" property is specified as a date with local time, then
the UNTIL rule part MUST also be specified as a date with local
time.  If the "DTSTART" property is specified as a date with UTC
time or a date with local time and time zone reference, then the
UNTIL rule part MUST be specified as a date with UTC time.

So in this example, I interpret the DTSTART as having a DATE value but the UNTIL is a DATE-TIME. So I think the interpretation of the RFC is correct but let me know if you disagree.

That said, i realize failing to parse a google calendar ics file probably makes this library useless to many, so I can work on updating this rule to coerce it to what is expected. I made a similar change in https://github.com/allenporter/gcal_sync/pull/176/files to a google calendar client library I maintain.