python-caldav / caldav

Apache License 2.0
314 stars 94 forks source link

Avoid crashing when object's component is missing #312

Closed flozz closed 1 year ago

flozz commented 1 year ago

Related issue: #310

This PR avoid a crash when the VCALENDAR does not contains a VEVENT component.

tobixen commented 1 year ago

Sorry for the late reply. You stated earlier that this workaround caused problems further downstream. I think my proposed (but totally untested) workaround at https://github.com/python-caldav/caldav/issues/310#issuecomment-1568622879 may be better, as it filters out those empty responses rather than just ignoring them.

Anyway, whatever floats the boat - if this workaround suffices for you, it is better than the current code anyway.

flozz commented 1 year ago

Sorry for the late reply.

No problem :)

You stated earlier that this workaround caused problems further downstream.

I only had some event with missing vevent object so I had to filter the event list with

events = [e for e in events if hasattr(e.instance, "vevent")]

I think my proposed (but totally untested) workaround at https://github.com/python-caldav/caldav/issues/310#issuecomment-1568622879 may be better, as it filters out those empty responses rather than just ignoring them.

It is probably better. I do not have enough time to test currently, but I will try to test it when I have some time. Anyway it is a step in the right direction and we can improve it later.

Thank you for the merge :)