diff --git a/caldav/davobject.py b/caldav/davobject.py index ab02bf63..7b6c6487 100644 --- a/caldav/davobject.py +++ b/caldav/davobject.py @@ -486,6 +486,7 @@ def set_properties(self, props: Any | None = None) -> "Self | Coroutine[Any, Any * props = [dav.DisplayName('name'), ...] + A failed property status in a Multi-Status response raises PropsetError. For async clients, returns a coroutine that must be awaited. Returns: @@ -519,9 +520,6 @@ def set_properties(self, props: Any | None = None) -> "Self | Coroutine[Any, Any ## A server applying PROPPATCH asynchronously (Infomaniak) keeps ## answering PROPFIND with the old value for a while; wait for it to go ## away rather than for the new one, which the server may normalise. - ## TODO: a property the server dropped (a 207 with a per-property 403 - ## or 404) never changes and costs the whole delay; poll only those - ## the PROPPATCH answered with 200. if old: query = [prop for prop in query if prop.tag in old] self._wait_until( @@ -587,7 +585,7 @@ def _still_old(old: dict, current: dict) -> bool: return any(current.get(tag) == value for tag, value in old.items()) def _post_set_properties(self, r) -> Self: - if r.status >= 400: + if r.status >= 400 or (r.status == 207 and not r.all_statuses_ok()): raise error.error_from_response(error.PropsetError, r) return self diff --git a/changes/792.fixed.md b/changes/792.fixed.md new file mode 100644 index 00000000..52f4137a --- /dev/null +++ b/changes/792.fixed.md @@ -0,0 +1 @@ +Raise PropsetError when a property write receives a failed status within an HTTP 207 response. diff --git a/tests/test_caldav_unit.py b/tests/test_caldav_unit.py index 62f5956b..3607bec8 100755 --- a/tests/test_caldav_unit.py +++ b/tests/test_caldav_unit.py @@ -8761,6 +8761,24 @@ def test_mkcalendar_failure_keeps_preconditions(self, method) -> None: assert exc_info.value.preconditions == [MKCALENDAR_TAG] assert exc_info.value.body + @pytest.mark.parametrize("status", ["200 OK", "403 Forbidden"]) + def test_proppatch_checks_each_property(self, base, status) -> None: + body = ( + '/cal/' + "HTTP/1.1 200 OK" + f"HTTP/1.1 {status}" + "" + ).encode() + client, sent = self._client(base, 207, body) + cal = Calendar(client, url=self.URL) + props = [dav.DisplayName("new"), cdav.CalendarDescription("overview")] + if status.startswith("200"): + assert self._run(cal.set_properties(props)) is cal + else: + with pytest.raises(error.PropsetError): + self._run(cal.set_properties(props)) + assert [method for method, _ in sent] == ["PROPPATCH"] + def test_proppatch_failure_keeps_preconditions(self) -> None: client = DAVClient(url=self.URL) with pytest.raises(error.PropsetError) as exc_info: