From 3612f8165e6703c55a4af8b40d22c1ca41ca9a19 Mon Sep 17 00:00:00 2001 From: Bart Feenstra Date: Fri, 1 Nov 2024 15:12:02 +0000 Subject: [PATCH] Use persistent IDs when creating derived events (#2179) --- betty/deriver.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/betty/deriver.py b/betty/deriver.py index 849ec727e..c7812123c 100644 --- a/betty/deriver.py +++ b/betty/deriver.py @@ -7,6 +7,7 @@ import logging from enum import Enum from typing import Iterable, cast +from uuid import uuid5, NAMESPACE_URL from betty.locale import DateRange, Date, Localizer from betty.model.ancestry import Person, Presence, Event, Subject, Ancestry @@ -32,6 +33,15 @@ class Derivation(Enum): UPDATE = 3 +def _derive_event_id(derivable_event_type: type[EventType], person: Person) -> str: + return str( + uuid5( + NAMESPACE_URL, + f"betty-deriver://{derivable_event_type.name()}/{person.id}", + ) + ) + + class Deriver: """ Derive information from ancestries, and create new entities or update existing ones. @@ -111,7 +121,13 @@ def _derive_person( self._lifetime_threshold, ): derivable_events = [ - (Event(event_type=derivable_event_type), Derivation.CREATE), + ( + Event( + id=_derive_event_id(derivable_event_type, person), + event_type=derivable_event_type, + ), + Derivation.CREATE, + ), ] else: return 0, 0