Repository navigation
Description
Disclosure: The root cause investigation and suggested fix were produced by an LLM from my traceback and RFCs 4791 / 4918. This was an interactive session, not an autonomous agent. I can personally confirm I hit the bug with Stalwart and Home Assistant's CalDAV integration.
We cannot turn on Stalwart's server-wide spec-breaking enableAssistedDiscovery setting, as it breaks other CalDAV clients like pimsync.
Stalwart source: https://github.com/stalwartlabs/stalwart
Below is LLM text:
Description
RFC 4791 §6.2.1 defines <!ELEMENT calendar-home-set (DAV:href*)>, so the property may hold more than one href. When a server returns more than one, get_principal().get_calendars() raises AttributeError: 'list' object has no attribute 'startswith'.
In current master, _element_to_value() in caldav/response.py returns a list for a multi-href calendar-home-set:
if tag == cdav.CalendarHomeSet.tag:
hrefs = [child.text for child in elem if child.tag == dav.Href.tag and child.text]
return hrefs[0] if len(hrefs) == 1 else hrefs_calendar_home_urls() in caldav/base_client.py passes that value to _make_absolute_url(), which expects a string:
calendar_home_url = extract_home_set(home_set_response.results, features=self.features)
if calendar_home_url:
urls = [self._make_absolute_url(calendar_home_url)]Server and setup
Stalwart offers two ways to expose calendars shared with a user from other accounts, controlled by the WebDav setting enableAssistedDiscovery:
- On (Stalwart's default): a
Depth: 1PROPFINDon the user's home (/dav/cal/bob/) also returns other accounts' collections, such as/dav/cal/jane/default/. This breaks RFC 4918.Depth: 1covers "the resource and its internal members only" (§10.2), and an internal member URL is "the URL of the collection (including trailing slash) plus the path segment identifying the internal member" (§3). Stalwart's source says so too (crates/dav/src/common/propfind/get.rs): "This is invalid but it's the only workaround for clients which do not support multiple home-sets." - Off:
build_home_set()incrates/dav/src/principal/propfind.rsreturns the user's own home first, then one href per account that shares calendars with them, all in onecalendar-home-set. The hrefs have the form/dav/cal/<account>/. This is the mode that triggers the crash.
So a server that avoids the spec-breaking discovery mode cannot be used with this library by any user who has shared calendars.
Traceback
Via Home Assistant's CalDAV integration on version 2026.11.3:
File ".../caldav/collection.py", line 728, in get_calendars
return self.client.get_calendars(self)
File ".../caldav/davclient.py", line 489, in get_calendars
for n, calendar_home_url in enumerate(self._calendar_home_urls(response, principal)):
File ".../caldav/base_client.py", line 468, in _calendar_home_urls
urls = [self._make_absolute_url(calendar_home_url)]
File ".../caldav/base_client.py", line 147, in _make_absolute_url
if url and not url.startswith("http"):
AttributeError: 'list' object has no attribute 'startswith'
Expected
get_calendars() returns the calendars found under every href in calendar-home-set.
Suggested fix
- In
_calendar_home_urls(), accept a list and make each href absolute. - In
DAVClient.get_calendars(), the loop currently stops at the first URL that yields calendars (if calendars: break). That suits the fallback guesses used when there's no home-set, but not real home-set hrefs. Those should all be queried and their results combined.
Activity
tobixen commentedon Dec 2, 2026
I've had Claude reproduce this with some unit tests. Although Stalwart is part of the test suite, it doesn't quite make sense to reproduce this in an integration test as it would require special configuration of Stalwart to reproduce the problem.
I'm soon going to bed, but I'll try to get the work done submitted so you can build a PR on top of it if you want.
tobixen commentedon Dec 2, 2026
Disclaimer: AI-generated text below the line, generated by Claude Opus 5.5, from the prompts:
Thanks for the report. Reproduced against a local Stalwart container: with
enableAssistedDiscoveryoff and a calendar shared fromuser1totestuserthrough a WebDAVACLrequest,testuser's principal answersand
get_calendars()crashes as described.principal.calendar_home_setcrashes too (the list reachesurllib), so it is not only theget_calendars()path, and the async client has its own copy of both. Failing unit tests are in draft PR #889; a Stalwart integration test would need the server-wide setting flipped in the docker setup, so it is left out for now.On the suggested fix, I think it is the right direction:
if calendars: breakinget_calendars()exists for the guessed URLs (principal URL, client URL) used when no home-set is given. Hrefs the server lists are authoritative, so combining their results is a different case, not a change to the fallback.The one thing I would keep:
principal.calendar_home_set(used bymake_calendar()and friends) should stay a single collection, the first href. Creating a calendar should not land in somebody else's home, and changing it to a list would be an API break. The draft tests encode that choice.test: calendar-home-set with several hrefs
fix: list calendars from every calendar-home-set