From e329979a5ef3ddec91b30ffdb2861a08d9fa7a16 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Sat, 14 Nov 2026 10:45:51 +0100 Subject: [PATCH 1/3] fix: Bedework stores the exception with its master caldav-server-tester graded save-load.event.recurrences.exception off a search, and Bedework's searches leave the exception out. Probed by a GET, Bedework 3.10 and 5 keep both in one object, so the hint is full for both. On Bedework 5, search() then expands on the client again, which search.recurrences.exception.in-calendar-data makes work. Prompt: Please fix the caldav-server-tester probe [ref https://github.com/python-caldav/caldav/pull/867] Assisted-By: Claude Opus 5.5 Reviewed-by: Tobias Brox --- caldav/compatibility_hints.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/caldav/compatibility_hints.py b/caldav/compatibility_hints.py index 7e19f38e..54fa5964 100644 --- a/caldav/compatibility_hints.py +++ b/caldav/compatibility_hints.py @@ -2050,10 +2050,12 @@ def __getattr__(name: str) -> Any: ## 5.x, hence the version-stamped name - a plain `bedework` would be claiming ## far more than we have measured. bedework_3_10_3 = { - ## Measured by hand 2026-11-14 (the conformance suite of calendaring): - ## a calendar-query returns the master without the moved occurrence, - ## which a GET of the same object has. + ## Probed 2026-11-14 by caldav-server-tester: a calendar-query returns + ## the master without the moved occurrence, which a GET of the same + ## object has. The object keeps both, so the exception is stored + ## (save-load.event.recurrences.exception was read off a search before). "search.recurrences.exception.in-calendar-data": {"support": "unsupported", "behaviour": "the calendar-data of a search holds the master only"}, + "save-load.event.recurrences.exception": {"support": "full"}, ## Measured with caldav-server-tester, 2026-10-27: the UID filter works although search.text does not. "search.text.uid": {"support": "full"}, ## Probed 2026-10-26 by caldav-server-tester: RFC 4791 section 5.2.3 makes @@ -2085,7 +2087,6 @@ def __getattr__(name: str) -> Any: 'auto-connect.url': {'basepath': '/ucaldav/'}, 'save-load.journal': {'support': 'ungraceful'}, 'save-load.todo.recurrences.thisandfuture': {'support': 'ungraceful'}, - 'save-load.event.recurrences.exception': {'support': 'unsupported'}, 'search.time-range.alarm': {'support': 'unsupported'}, "freebusy-query": True, "search.time-range.todo": False, @@ -2146,10 +2147,12 @@ def __getattr__(name: str) -> Any: ## deletes calendars, its sync-token and text search behave differently - so ## nothing is inherited from that profile. bedework_5_0_0 = { - ## Measured by hand 2026-11-14 (the conformance suite of calendaring): - ## a calendar-query returns the master without the moved occurrence, - ## which a GET of the same object has. + ## Probed 2026-11-14 by caldav-server-tester: a calendar-query returns + ## the master without the moved occurrence, which a GET of the same + ## object has. The object keeps both, so the exception is stored + ## (save-load.event.recurrences.exception was read off a search before). "search.recurrences.exception.in-calendar-data": {"support": "unsupported", "behaviour": "the calendar-data of a search holds the master only"}, + "save-load.event.recurrences.exception": {"support": "full"}, ## Probed 2026-11-12 by caldav-server-tester, and by hand on a fresh ## container: a PUT with one ATTENDEE gives two identical ATTENDEE lines ## in GET and calendar-multiget alike. @@ -2222,7 +2225,6 @@ def __getattr__(name: str) -> Any: ## user with a working `tasks` collection may well see this work. "search.time-range.todo": {"support": "unknown"}, - "save-load.event.recurrences.exception": {"support": "unsupported"}, ## Seen 2026-09-13 in testChangeAttendeeStatusWithEmailGiven, which only ## started running once save-load.mutable.attendee-partstat came out full. "save-load.event.no-summary": { From 2ef006351e9e7f1cd264ed82913fefbf724edcd3 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Sat, 14 Nov 2026 12:08:25 +0100 Subject: [PATCH 2/3] feat: load(fallbacks=False) loads by the GET alone After a 404 for an object with a UID, load() tries a multiget and then a search by UID, the latter even with multiget_fallback=False. A caller comparing a GET with a search, as caldav-server-tester does to grade search.recurrences.exception.in-calendar-data, then may get a search for its GET. With the new fallbacks=False, a failed GET raises. Prompt: Make a workaround in the caldav libary (sic) ... `def load(..., multiget_fallback=True)` [from the review of the tester probe: load() can fall back to a multiget or a search by UID] Followup-Prompt: (answer to a clarifying question) An option for "skip every fallback" needs another name, but let's go for it. Assisted-By: Claude Opus 5.5 Reviewed-by: Tobias Brox --- caldav/calendarobjectresource.py | 29 ++++++++++++++++++------ caldav/compatibility_hints.py | 4 ++-- changes/+load-fallbacks.added.md | 1 + tests/test_async_davclient.py | 39 ++++++++++++++++++++++++++++++++ tests/test_caldav_unit.py | 27 ++++++++++++++++++++++ 5 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 changes/+load-fallbacks.added.md diff --git a/caldav/calendarobjectresource.py b/caldav/calendarobjectresource.py index 774aa389..138cd55c 100644 --- a/caldav/calendarobjectresource.py +++ b/caldav/calendarobjectresource.py @@ -981,7 +981,10 @@ def copy(self, keep_uid: bool = False, new_parent: Any | None = None) -> Self: ## TODO: move get-logics to a load_by_get method. ## The load method should deal with "server quirks". def load( - self, only_if_unloaded: bool = False, multiget_fallback: bool = True + self, + only_if_unloaded: bool = False, + multiget_fallback: bool = True, + fallbacks: bool = True, ) -> "Self | Coroutine[Any, Any, Self]": """ (Re)load the object from the caldav server. @@ -999,6 +1002,13 @@ def load( on by default. Pass False to see what the server itself answered - a compatibility checker probing whether a missing object really raises NotFoundError needs the unrescued error. + A 404 for an object with a UID is still retried as a search by + UID; fallbacks=False is the GET alone. + :param fallbacks: False loads by the GET and nothing else: no + multiget, and no search by UID after a 404 for an object that + has one (which multiget_fallback=False still does). For a + caller that needs the server's own answer to the GET, such as a + compatibility checker comparing it with what a search returns. Example (sync): obj.load() @@ -1021,7 +1031,9 @@ def load( # Dual-mode support: async clients return a coroutine if self.is_async_client: return self._async_load( - only_if_unloaded=only_if_unloaded, multiget_fallback=multiget_fallback + only_if_unloaded=only_if_unloaded, + multiget_fallback=multiget_fallback, + fallbacks=fallbacks, ) if self.url is None: @@ -1040,7 +1052,7 @@ def load( # (has a UID), indicating the server may have changed the URL. # Without a UID, the 404 is definitive. uid = self.id - if uid: + if uid and fallbacks: # Fallback 1: try multiget (REPORT may work even when GET fails) if multiget_fallback: try: @@ -1062,7 +1074,7 @@ def load( pass raise except Exception: - if not multiget_fallback: + if not (multiget_fallback and fallbacks): raise return self.load_by_multiget() @@ -1070,7 +1082,10 @@ def load( return self async def _async_load( - self, only_if_unloaded: bool = False, multiget_fallback: bool = True + self, + only_if_unloaded: bool = False, + multiget_fallback: bool = True, + fallbacks: bool = True, ) -> Self: """Async implementation of load.""" if only_if_unloaded and self.is_loaded(): @@ -1089,7 +1104,7 @@ async def _async_load( self._keep_raw_data(getattr(r, "_raw_body", None)) except error.NotFoundError: uid = self.id - if uid: + if uid and fallbacks: # Fallback 1: try multiget (REPORT may work even when GET fails) if multiget_fallback: try: @@ -1111,7 +1126,7 @@ async def _async_load( pass raise except Exception: - if not multiget_fallback: + if not (multiget_fallback and fallbacks): raise return await self.load_by_multiget() diff --git a/caldav/compatibility_hints.py b/caldav/compatibility_hints.py index 54fa5964..84174688 100644 --- a/caldav/compatibility_hints.py +++ b/caldav/compatibility_hints.py @@ -557,8 +557,8 @@ class FeatureSet: "REPORT against the parent collection, and a server answering 403 on the object " "URL may report the missing href with a 404 inside that multistatus (Robur does); " "read the `behaviour` field for what a given server does. Anything reaching past " - "`load()` sees the raw answer, and `load(multiget_fallback=False)` asks for it " - "deliberately. 'unsupported' when the lookup ends in some other DAVError - " + "`load()` sees the raw answer, and `load(fallbacks=False)` asks for it " + "deliberately (`multiget_fallback=False` still retries a 404 as a search by UID). 'unsupported' when the lookup ends in some other DAVError - " "typically AuthorizationError, because the server answers 403 rather than 404 to " "avoid leaking whether a resource exists, which is a legitimate choice rather " "than an RFC breach, hence 'unsupported' rather than 'broken'." diff --git a/changes/+load-fallbacks.added.md b/changes/+load-fallbacks.added.md new file mode 100644 index 00000000..bcfcd8db --- /dev/null +++ b/changes/+load-fallbacks.added.md @@ -0,0 +1 @@ +New parameter `CalendarObjectResource.load(fallbacks=True)`. Set it to `False` to load by the GET alone: no calendar-multiget and no search by UID when the GET fails, which `multiget_fallback=False` still does after a 404. diff --git a/tests/test_async_davclient.py b/tests/test_async_davclient.py index 6a2cf99e..61d625cb 100644 --- a/tests/test_async_davclient.py +++ b/tests/test_async_davclient.py @@ -1131,6 +1131,45 @@ async def test_load_without_multiget_fallback_raises_the_servers_own_error(self) await event.load(multiget_fallback=False) multiget.assert_not_awaited() + @pytest.mark.asyncio + async def test_load_without_fallbacks_raises_the_servers_own_error(self) -> None: + """fallbacks=False surfaces the 403 and sends no REPORT.""" + from caldav.aio import AsyncCalendarObjectResource + + event = self._forbidden_event() + with patch.object( + AsyncCalendarObjectResource, "load_by_multiget", new_callable=AsyncMock + ) as multiget: + with pytest.raises(error.AuthorizationError): + await event.load(fallbacks=False) + multiget.assert_not_awaited() + + @pytest.mark.asyncio + async def test_load_without_fallbacks_raises_a_404_for_an_object_with_a_uid(self) -> None: + """fallbacks=False: no multiget and no search by UID after a 404.""" + from caldav.aio import AsyncCalendarObjectResource, AsyncEvent + from caldav.collection import Calendar + + client = AsyncDAVClient(url="https://caldav.example.com/dav/") + client.request = AsyncMock(side_effect=error.NotFoundError("404 Not Found")) + calendar = Calendar(client=client, url="https://caldav.example.com/dav/calendars/test/") + event = AsyncEvent( + client=client, + url="https://caldav.example.com/dav/calendars/test/x.ics", + parent=calendar, + data="BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//x//y//EN\r\nBEGIN:VEVENT\r\nUID:x\r\nDTSTAMP:20260101T000000Z\r\nDTSTART:20260101T000000Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", + ) + with ( + patch.object( + AsyncCalendarObjectResource, "load_by_multiget", new_callable=AsyncMock + ) as multiget, + patch.object(Calendar, "get_object_by_uid", new_callable=AsyncMock) as by_uid, + ): + with pytest.raises(error.NotFoundError): + await event.load(fallbacks=False) + multiget.assert_not_awaited() + by_uid.assert_not_awaited() + class TestAsyncRateLimiting: """ diff --git a/tests/test_caldav_unit.py b/tests/test_caldav_unit.py index 28b117aa..f9460abd 100755 --- a/tests/test_caldav_unit.py +++ b/tests/test_caldav_unit.py @@ -630,6 +630,33 @@ def testLoadWithoutMultigetFallbackRaisesTheServersOwnError(self): with pytest.raises(error.AuthorizationError): object.load(multiget_fallback=False) + def testLoadWithoutFallbacksRaisesA404ForAnObjectWithAUid(self): + """load(fallbacks=False) is the GET and nothing else. + + A 404 for an object that has a UID is otherwise retried as a multiget + and then as a search by UID - the latter whatever multiget_fallback + says. A compatibility checker comparing what a GET returns with what + a search returns must not get a search for its GET. + """ + client = DAVClient(url="http://cal.example.com/") + client.request = mock.Mock(side_effect=error.NotFoundError("404 Not Found")) + calendar = Calendar(client, url="/calendar/") + event = Event(client=client, url="/calendar/x.ics", parent=calendar, data=ev1) + with ( + mock.patch.object(Calendar, "get_object_by_uid") as by_uid, + mock.patch.object(Event, "load_by_multiget") as multiget, + ): + with pytest.raises(error.NotFoundError): + event.load(fallbacks=False) + by_uid.assert_not_called() + multiget.assert_not_called() + + def testLoadWithoutFallbacksRaisesAForbidden(self): + """fallbacks=False also leaves a refused GET unrescued.""" + object = self._robur_object(self.MULTIGET_FOUND, "/calendar/robur/found.ics") + with pytest.raises(error.AuthorizationError): + object.load(fallbacks=False) + def testTheMultigetFallbackDoesNotLaunderARealForbidden(self): """A genuine 403 does not come out of the multiget fallback as a 404. From 7ff9b3176c04b91eae916b926e9f93590230e613 Mon Sep 17 00:00:00 2001 From: Tobias Brox Date: Sat, 14 Nov 2026 12:12:08 +0100 Subject: [PATCH 3/3] fix: keep a server expansion out of the reload Where search.recurrences.exception.in-calendar-data is unsupported, search() loads the recurring objects it found again. After a server-side expansion, each instance carries a RECURRENCE-ID and was taken for one, and the multiget swapped the occurrences for the unexpanded master and exception. search(server_expand=True) without expand=True then returned the raw objects on Bedework 5. Prompt: [fix issues found during the review process] Assisted-By: Claude Opus 5.5 Reviewed-by: Tobias Brox --- caldav/search.py | 5 ++++- tests/test_caldav_unit.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/caldav/search.py b/caldav/search.py index dd1dd88a..a9bbeb10 100644 --- a/caldav/search.py +++ b/caldav/search.py @@ -1128,11 +1128,14 @@ def _search_impl( return # Bedework leaves the exceptions out of the calendar-data of a search. - # Only what the search itself returned; the batch load below fetches whole objects + # Only what the search itself returned; the batch load below fetches whole objects. + # Not after a server-side expansion: its instances carry a RECURRENCE-ID, and a + # multiget would swap them for the unexpanded master and exception partial = [] if ( cw and not caller_chose_data + and not server_expand and not calendar.client.features.is_supported( "search.recurrences.exception.in-calendar-data" ) diff --git a/tests/test_caldav_unit.py b/tests/test_caldav_unit.py index f9460abd..0addb3d0 100755 --- a/tests/test_caldav_unit.py +++ b/tests/test_caldav_unit.py @@ -10129,6 +10129,31 @@ def test_no_second_request_elsewhere(self, base) -> None: ) assert requests == ["query"] + def test_a_server_expansion_is_not_loaded_again(self, base) -> None: + """Expanded on the server, each instance carries a RECURRENCE-ID: a + multiget would swap them for the unexpanded master and exception.""" + instances = "".join( + "BEGIN:VEVENT\r\nUID:series-1\r\nDTSTAMP:20260101T000000Z\r\n" + f"RECURRENCE-ID:202611{day:02d}T090000Z\r\n" + f"DTSTART:202611{day:02d}T{hour}0000Z\r\nDTEND:202611{day:02d}T{hour + 1}0000Z\r\n" + f"SUMMARY:R: {'moved' if day == 3 else 'daily'}\r\nEND:VEVENT\r\n" + for day, hour in ((1, 9), (2, 9), (3, 14), (4, 9), (5, 9)) + ) + features = { + "search.recurrences.expanded": {"support": "full"}, + "search.recurrences.exception.in-calendar-data": {"support": "unsupported"}, + } + summaries, requests = self._search( + base, + features, + expand=False, + query=self.HEAD + instances + self.TAIL, + search_kwargs={"server_expand": True}, + ) + assert requests == ["query"] + assert ("2026-11-03 09:00:00+00:00", "R: moved") in summaries + assert len(summaries) == 5 + def test_a_one_off_event_in_a_zone_is_not_loaded_again(self, base) -> None: one_off = self.HEAD + self.ONE_OFF + self.TAIL summaries, requests = self._search(base, query=one_off, full=one_off)