Skip to content

Commit c0f06d8

Browse files
tobixenclaude
andcommitted
Fix add_object/add_event/add_todo for async clients (issue #631)
When using AsyncDAVClient, CalendarObjectResource.save() returns a coroutine. Collection.add_object() was calling o.save() and then immediately accessing o.url, crashing with AttributeError because o was a coroutine, not the saved object. Fix by routing through _async_add_object_finish() when is_async_client, which awaits save() before checking o.url and calling _handle_reverse_relations(). Fixes #631 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4d588c9 commit c0f06d8

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

caldav/collection.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,8 @@ def add_object(
840840
),
841841
parent=self,
842842
)
843+
if self.is_async_client:
844+
return self._async_add_object_finish(o, no_overwrite=no_overwrite, no_create=no_create)
843845
o = o.save(no_overwrite=no_overwrite, no_create=no_create)
844846
## TODO: Saving nothing is currently giving an object with None as URL.
845847
## This should probably be changed in some future version to raise an error
@@ -848,6 +850,13 @@ def add_object(
848850
o._handle_reverse_relations(fix=True)
849851
return o
850852

853+
async def _async_add_object_finish(self, o, no_overwrite=False, no_create=False):
854+
"""Async helper for add_object(): awaits save() then handles reverse relations."""
855+
o = await o.save(no_overwrite=no_overwrite, no_create=no_create)
856+
if o.url is not None:
857+
o._handle_reverse_relations(fix=True)
858+
return o
859+
851860
def add_event(self, *largs, **kwargs) -> "Event":
852861
"""
853862
Add an event to the calendar.

0 commit comments

Comments
 (0)