From c2a4b946fb63280798769a68edbd446a918bf7d0 Mon Sep 17 00:00:00 2001
From: Felix Blanke <info@fblanke.de>
Date: Wed, 26 Feb 2025 17:32:23 +0100
Subject: [PATCH] Add inconsistency check

---
 AKModel/models.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/AKModel/models.py b/AKModel/models.py
index fc2157a3..a25e0b05 100644
--- a/AKModel/models.py
+++ b/AKModel/models.py
@@ -412,7 +412,7 @@ class Event(models.Model):
             yield from self.uniform_time_slots(slots_in_an_hour=slots_in_an_hour)
 
     @transaction.atomic
-    def schedule_from_json(self, schedule: str) -> int:
+    def schedule_from_json(self, schedule: str, *, check_for_data_inconsistency: bool = True) -> int:
         """Load AK schedule from a json string.
 
         :param schedule: A string that can be decoded to json, describing
@@ -421,6 +421,10 @@ class Event(models.Model):
             https://github.com/Die-KoMa/ak-plan-optimierung/wiki/Input-&-output-format
         """
         schedule = json.loads(schedule)
+        export_dict = self.as_json_dict()
+
+        if check_for_data_inconsistency and schedule["input"] != export_dict:
+            raise ValueError("Data has changed since the export. Reexport and run the solver again.")
 
         slots_in_an_hour = schedule["input"]["timeslots"]["info"]["duration"]
 
-- 
GitLab