From feaebc90e21e8b2e66b58fa9a32b7fab7de164b7 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Fri, 24 Dec 2021 14:33:12 +0100
Subject: [PATCH] TMSS-671: removed obsolete
 self.__original_scheduling_constraints_template_id and
 self.__original_scheduling_constraints_doc. Removed addidion of non-required
 defaults to constraints_doc, which can have side effects the user did not
 intent

---
 .../src/tmss/tmssapp/models/specification.py  | 28 ++++---------------
 1 file changed, 6 insertions(+), 22 deletions(-)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
index f703226a527..6732f1c0584 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
@@ -609,7 +609,9 @@ class SchedulingUnitDraft(NamedCommon, TemplateSchemaMixin, ProjectPropertyMixin
             if self.piggyback_allowed_aartfaac is None and hasattr(self, 'scheduling_set'):
                 self.piggyback_allowed_aartfaac = self.scheduling_set.project.piggyback_allowed_aartfaac
 
-        self.annotate_validate_add_defaults_to_doc_using_template('scheduling_constraints_doc', 'scheduling_constraints_template')
+        # we intentionally do not add defaults to scheduling_constraints_doc
+        # because that would add default items which the user did not specify,
+        # and for scheduling contraints this can have unforeseen sideeffects that the user did not intent.
 
         super().save(force_insert, force_update, using, update_fields)
 
@@ -744,21 +746,6 @@ class SchedulingUnitBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCo
     global_identifier = OneToOneField('SIPidentifier', null=False, editable=False, on_delete=PROTECT, help_text='The global unique identifier for LTA SIP.')
     path_to_project = 'draft__scheduling_set__project'
 
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
-
-        # keep original scheduling constraints to detect changes on save
-        # Note: we cannot use self.scheduling_constraints_doc here since that causes an infinite loop of update_from_db
-        if 'scheduling_constraints_doc' in kwargs.keys():
-            self.__original_scheduling_constraints_doc = kwargs['scheduling_constraints_doc']
-        else:
-            field_names = [f.name for f in self._meta.fields]
-            if len(args) == len(field_names):
-                self.__original_scheduling_constraints_doc = args[field_names.index('scheduling_constraints_doc')]
-            else:
-                self.__original_scheduling_constraints_doc = None
-        self.__original_scheduling_constraints_template_id = self.scheduling_constraints_template_id
-
     def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
         SIPidentifier.assign_new_id_to_model(self)
 
@@ -769,12 +756,9 @@ class SchedulingUnitBlueprint(ProjectPropertyMixin, TemplateSchemaMixin, NamedCo
                 if hasattr(self, 'draft'):
                     setattr(self, copy_field, getattr(self.draft, copy_field))
 
-        # make sure the scheduling_constraints_doc contains all required and default values. (no-op when already complete)
-        self.annotate_validate_add_defaults_to_doc_using_template('scheduling_constraints_doc', 'scheduling_constraints_template')
-
-        # update the original constraints value for comparison on next save
-        self.__original_scheduling_constraints_doc = self.scheduling_constraints_doc
-        self.__original_scheduling_constraints_template_id = self.scheduling_constraints_template_id
+        # we intentionally do not add defaults to scheduling_constraints_doc
+        # because that would add default items which the user did not specify,
+        # and for scheduling contraints this can have unforeseen sideeffects that the user did not intent.
 
         if self._state.adding and self.interrupts_telescope:
             if self.project.can_trigger:
-- 
GitLab