Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event.get_uid() doesn't work when event is constructed from builder functions #110

Open
mushrowan opened this issue Sep 1, 2024 · 4 comments

Comments

@mushrowan
Copy link

mushrowan commented Sep 1, 2024

When an event is constructed as follows:

let mut event = Event::new();
event = event.summary("testing").starts(start_time).ends(end_time).done();
dbg!(&event.to_string());

the debug clearly shows the event body as having a UID. However:
let event_uid = event.get_uid().unwrap();
This panics. I'd assume setting the uid manually with uid() would work, but I don't want to do this. Perhaps I'm doing something wrong here, which of course I'm open to, but this doesn't seem like intended functionality.

edit: looks like the UID property isn't getting populated at all on event creation - event.properties() doesn't have UID and event.property_value("UID").unwrap() panics too.

@hoodie
Copy link
Owner

hoodie commented Sep 2, 2024

Yes the default behavior right now is that you have to set that yourself. I was thinking for a bit what could be a safe default to generate a UID from something in the event data but haven't found a good approach yet. Also the lib can't just gehst generate a random uuid either, since you'd get a different uid for the same event every time you regenerate the calendar. So at the moment the crate leaves it to the user to fill out the uid.

@mushrowan
Copy link
Author

that's fair. the weird thing really is that if you debug the string created by &Event.to_string(), it does have a uid there. So I imagine something somewhere is creating this uid, but I haven't looked at the codebase enough to figure out where that's coming from. Any ideas?

@hoodie
Copy link
Owner

hoodie commented Sep 2, 2024

yes, actually in the serialization we check if there is a UID and if not we create a UUID to fill it.
According to RFC5545 3.8.4.7 :

The property MUST be specified in the "VEVENT",
"VTODO", "VJOURNAL", or "VFREEBUSY" calendar components.

So we generate one at serialization time.

I'm not super happy with this approach, but it is probably sufficient for a one time generation. But if you serve an iCalendar you will want to generate them yourself in order to get a stable UID.

If you have a better idea please let me know.

@ThomasdenH
Copy link
Contributor

This can probably be solved by seperating the builder as in #35! Then you can use the user supplied UID or generate one when build() is called. A generated Event can then always have a UID.

Optionally, there could be an Event::regenerate_uid() to make sure that it is always possible to get the UID that would be automatically generated even if changing properties afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants