Skip to content

Commit d9f42d1

Browse files
authored
Retry PUT 409 errors - delete and re-create event
Attempt to address #963 I would appreciate a code review here - there might be a more elegant way to address this problem, but it works for my (very limited) use case.
1 parent 68c5968 commit d9f42d1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

vdirsyncer/storage/dav.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,16 @@ async def _put(self, href, item, etag):
587587
async def update(self, href, item, etag):
588588
if etag is None:
589589
raise ValueError("etag must be given and must not be None.")
590-
href, etag = await self._put(self._normalize_href(href), item, etag)
590+
try:
591+
href, etag = self._put(self._normalize_href(href), item, etag)
592+
except HTTPError as e:
593+
if e.response.status_code == 409:
594+
dav_logger.debug("Conflict, will delete old event and recreate it.")
595+
self.delete(self._normalize_href(href), etag)
596+
dav_logger.debug("Now trying again")
597+
href, etag = self._put(self._normalize_href(href), item, None)
598+
else:
599+
raise e
591600
return etag
592601

593602
async def upload(self, item: Item):

0 commit comments

Comments
 (0)