Skip to content

get_supported_components throws error if tag is missing #653

@ColonelThirtyTwo

Description

@ColonelThirtyTwo

I'm getting this error from HomeAssistant's CalDav integration, which uses this library:

Error while setting up caldav platform for calendar: '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 455, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/usr/src/homeassistant/homeassistant/components/caldav/calendar.py", line 158, in async_setup_entry
    calendars = await async_get_calendars(hass, entry.runtime_data, SUPPORTED_COMPONENT)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/caldav/api.py", line 20, in async_get_calendars
    return await hass.async_add_executor_job(_get_calendars)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/concurrent/futures/thread.py", line 86, in run
    result = ctx.run(self.task)
  File "/usr/local/lib/python3.14/concurrent/futures/thread.py", line 73, in run
    return fn(*args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/caldav/api.py", line 17, in _get_calendars
    if component in calendar.get_supported_components()
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.14/site-packages/caldav/collection.py", line 500, in get_supported_components
    prop = response_list[unquote(self.url.path)][
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        cdav.SupportedCalendarComponentSet().tag
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ]
    ^
KeyError: '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'

RFC 4791 specifies that "This property MAY be defined on any calendar collection", so it is an optional element. However, Calendar.get_supported_components uses a standard attribute access to get the element in the fallback path, which fails with a KeyError if it does not exist.

get_supported_components should gracefully handle this case and return an empty list if the tag is missing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions