Help needed with updating an existent event #547
-
|
Hello, I'm having some issue understanding what I'm doing wrong while trying to update an existing remote event. My use-case: I'm using this library in a Telegram chatbot that listens for messages in a channel, and creates events in a shared calendar when some criteria are met. When a message that previously originated a calendar event is edited by its sender, the corresponding event's properties are updated too, if necessary. Creating an event works without issues. I'm storing the created events' This is a minimal example that shows what I'm doing, and the logs output. Everything here is done in sequence, but in the scenario I described, event creation and event editing are done asynchronously, based on the user interaction. import datetime
import logging
import time
from caldav.davclient import get_davclient
from icalendar import Event
logging.basicConfig(
format="%(asctime)s [%(name)s][%(levelname)s] %(message)s",
level=logging.DEBUG
)
logger = logging.getLogger(__name__)
def to_ical_str(instance) -> str:
return instance.to_ical().decode("utf-8")
def main() -> None:
client = get_davclient() # creds are set using the CALDA_* env variables
principal = client.principal()
calendar = principal.calendar(cal_id="Y2FsOi8vMC81NQ") # id of the test calendar I'm using
event = Event()
event.add("summary", "halloween party ^^")
dt_start = datetime.date(2025, 10, 31)
event.add("dtstart", dt_start) # as date() -> full-day event
event.add("dtend", dt_start + datetime.timedelta(days=1))
# add some other generic properties
event.add("description", "bring your best costume :p")
event.add("categories", ["party"])
event.add("sequence", 1) # not sure if it is needed to later update the event, we set it regardless
caldav_event = calendar.save_event(to_ical_str(event))
logger.info(f"created event with uid {caldav_event.id} in calendar {calendar.id}")
# avoid rate limiting
nap_time_seconds = 5
logger.info(f"sleeping for {nap_time_seconds} seconds")
time.sleep(nap_time_seconds)
# trying to request the caldav object again, by event uid
fetched_caldav_event = calendar.object_by_uid(caldav_event.id)
logger.info(f"icalendar event fetched by uid:\n{to_ical_str(fetched_caldav_event.icalendar_component)}")
# edit the title of the icalendar Event instance
fetched_caldav_event.icalendar_component["summary"] = "halloween party 2025 ^^" # new summary/title (added "2025")
fetched_caldav_event.icalendar_component["sequence"] = 4 # not sure if it is needed to later update the event, we set it regardless to an higher value
logger.info(f"edited icalendar event we will use to update the existing one:\n{to_ical_str(fetched_caldav_event.icalendar_component)}")
# override the data property with the updated icalendar string
fetched_caldav_event.data = to_ical_str(fetched_caldav_event.icalendar_component)
fetched_caldav_event.save(increase_seqno=True)
if __name__ == "__main__":
main()The console output: The remote event's summary, btw, is not updated. Judging from the urllib logs, it looks like something's wrong with the data passed to I'm running this from python 3.13, Any help is appreciated. If more details are needed I will be glad to provide them Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Well, I figured it out. To push an edited event back to the server, I need to wrap it in a This updates the remove event: ...
# edit the title of the icalendar Event instance
fetched_caldav_event.icalendar_component["summary"] = "halloween party 2025 ^^" # new summary/title (added "2025")
fetched_caldav_event.icalendar_component["sequence"] = 4 # not sure if it is needed to later update the event, we set it regardless to an higher value
logger.info(f"edited icalendar event we will use to update the existing one:\n{to_ical_str(fetched_caldav_event.icalendar_component)}")
# wrap the event in a VCALENDAR
cal = Calendar()
cal.add("PRODID", "-//MyApp//EN")
cal.add("VERSION", "2.0")
cal.add_component(fetched_caldav_event.icalendar_component)
# override the data property with the updated icalendar VCALENDAR
fetched_caldav_event.data = cal.to_ical()
fetched_caldav_event.save(increase_seqno=True) |
Beta Was this translation helpful? Give feedback.
-
|
This seems related to issue #546 |
Beta Was this translation helpful? Give feedback.
Well, I figured it out. To push an edited event back to the server, I need to wrap it in a
VCALENDARand then send it back.This updates the remove event:
... # edit the title of the icalendar Event instance fetched_caldav_event.icalendar_component["summary"] = "halloween party 2025 ^^" # new summary/title (added "2025") fetched_caldav_event.icalendar_component["sequence"] = 4 # not sure if it is needed to later update the event, we set it regardless to an higher value logger.info(f"edited icalendar event we will use to update the existing one:\n{to_ical_str(fetched_caldav_event.icalendar_component)}") # wrap the event in a VCALENDAR cal = Calendar() c…