Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions caldav/davobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions changes/792.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise PropsetError when a property write receives a failed status within an HTTP 207 response.
18 changes: 18 additions & 0 deletions tests/test_caldav_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
'<multistatus xmlns="DAV:"><response><href>/cal/</href>'
"<propstat><prop><displayname/></prop><status>HTTP/1.1 200 OK</status></propstat>"
f"<propstat><prop><calendar-description xmlns='urn:ietf:params:xml:ns:caldav'/></prop><status>HTTP/1.1 {status}</status>"
"</propstat></response></multistatus>"
).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:
Expand Down
Loading