UID field of new local event overwritten on first sync

I'm not sure if this is the right place for this, but I figured I'd try. It looks to me that DAVdroid is overwriting the UID on calendar events upon sync. Is this the intended behaviour? It seems to me that this would cause problems when several ICS files that all reference the same UID are imported into the calendar over time. DAVdroid seems to be changing the UID and one would be unable to connect later ICS files referencing the original UID to the calendar event in question.

It seems to me that perhaps DAVdroid should only be generating and setting a UID on the calendar event if there isn't one already.

I'm importing ICS files received via email. I have two ICS files that I'm currently testing, one that creates the appointment (it contains a UID that doesn't exist in the calendar), and one that updates the appointment (it contains the same UID as the previous ICS file). I import the first one successfully, but when the second one is imported, the UID of the event created when the first one was imported has changed.

It only occurs to me now that it's possible Nextcloud is changing the UID. I poked through the source of DAVdroid and found LocalEvent.updateFileNameAndUID() - this led me to post here.

You're right. The only case when LocalEvent.updateFileNameAndUID() is called is when DAVdroid looks for new local events (SyncManager.prepareDirty()), so that it can generate an UID and a file name before uploading them.

At the moment, DAVdroid doesn't expect new local events with Events.UID_2445, so it generates an UID (Events.UID_2445) and file name (Events._SYNC_ID) and overwrites these fields. This only happens when an event is created locally.

So, to reflect the possibility that events are already created with an UID_2445, this field should be checked and only set when there's no value yet.