diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py index dddaeb30ee9f70cc58dcb102fd4a9ffd078836c4..19a1b2f6dc705c346faf710a63abf5cb83a16d70 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/common.py @@ -195,7 +195,6 @@ class AbstractTemplate(NamedCommon): So, update the version number if the template is already used, else keep it. Returns a tuple of the previous and new version number (which can be equal if there was no need to update it)''' if self._need_to_auto_increment_version_number: - self.pk = None # this forces the creation of a new instance same_name_obj = self.__class__.objects.filter(name=self.name).order_by('-version').first() old_version = self.version new_version = same_name_obj.version + 1 if same_name_obj is not None else 1 @@ -445,6 +444,9 @@ class AbstractSchemaTemplate(AbstractTemplate): # prevent duplicates raise ValueError("%s name='%s' version=%s has a new schema which is already known in version=%s" % (self.__class__.__name__, old_version, newer_version)) + # the new version needs to be saved in a new instance + self.pk = None # this forces the creation of a new instance + self.annotate_and_validate_json_schema() super().save(force_insert or self.pk is None, force_update, using, update_fields) diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py index f442f947609de3832d6a4c3057ed4d12f5244dd8..e37378d2739b760392d9a43e971117384e8d13f6 100644 --- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py +++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py @@ -1290,7 +1290,7 @@ class SchedulingUnitCommonPropertiesMixin: def validate_scheduling_constraints(self): '''validate the scheduling_constraints_doc against its template, and for additional consistency checks''' - if self.scheduling_constraints_template is None or self.scheduling_constraints_doc is None: + if self.scheduling_constraints_template is None or not self.scheduling_constraints_doc: return self.scheduling_constraints_template.validate_document(self.scheduling_constraints_doc) diff --git a/SAS/TMSS/backend/test/t_scheduling_units.py b/SAS/TMSS/backend/test/t_scheduling_units.py index 4798eb81d378f27a78e677e1fb8630b4573ef111..bbd25ff0d4eb09b23bf322a95fec97096b30ffbb 100644 --- a/SAS/TMSS/backend/test/t_scheduling_units.py +++ b/SAS/TMSS/backend/test/t_scheduling_units.py @@ -225,7 +225,7 @@ class SchedulingUnitBlueprintStateTest(unittest.TestCase): task_state_dict = {} for test_item in test_table: # Create schedulingblueprint - schedulingunit_data = SchedulingUnitBlueprint_test_data(name="Task Blueprint With Three Tasks") + schedulingunit_data = SchedulingUnitBlueprint_test_data(name="Task Blueprint With Three Tasks", specifications_template=models.SchedulingUnitTemplate.get_latest("scheduling unit")) schedulingunit_blueprint = models.SchedulingUnitBlueprint.objects.create(**schedulingunit_data) # Create related task and subtasks tasks_and_subtasks_dict = self.create_tasks_and_subtasks(schedulingunit_blueprint) @@ -1027,29 +1027,24 @@ class SchedulingUnitBlueprintIndirectModificationsTestCase(unittest.TestCase): obs_specifications_doc['QA']['plots']['enabled'] = False obs_specifications_doc['station_configuration']['SAPs'][0]['subbands'] = [0, 1, 2, 3] - specifications_doc = { - "tasks": { "observation": { "specifications_doc": obs_specifications_doc, - "specifications_template": {"name": "target observation", "version": 2 }}, - "pipeline": { "description": "my description", - "specifications_doc": {}, - "specifications_template": {"name": "preprocessing pipeline", "version": 2 }}, - }, - "task_relations": [ { "input": { "role": "any", - "datatype": "visibilities", - "dataformat": "MeasurementSet" }, - "output": { "role": "correlator", - "datatype": "visibilities", - "dataformat": "MeasurementSet" }, - "consumer": "pipeline", - "producer": "observation", - "selection_doc": {}, - "selection_template": {"name": "all", "version": 2 } } - ], - "task_scheduling_relations": [] - } - su_template = models.SchedulingUnitTemplate.get_latest("scheduling unit") - specifications_doc['$schema'] = su_template.schema['$id'] + specifications_doc = su_template.get_default_json_document_for_schema() + + specifications_doc["tasks"] = { "observation": { "specifications_doc": obs_specifications_doc, + "specifications_template": {"name": "target observation", "version": 2 }}, + "pipeline": { "description": "my description", + "specifications_doc": {}, + "specifications_template": {"name": "preprocessing pipeline", "version": 2 }}} + specifications_doc["task_relations"] = [ { "input": { "role": "any", + "datatype": "visibilities", + "dataformat": "MeasurementSet" }, + "output": { "role": "correlator", + "datatype": "visibilities", + "dataformat": "MeasurementSet" }, + "consumer": "pipeline", + "producer": "observation", + "selection_doc": {}, + "selection_template": {"name": "all" } } ] scheduling_unit_draft = client.create_scheduling_unit_draft_from_specifications_doc("test_rerun_copy_of_failed_tasks_excludes_observation", "no description", scheduling_set['id'], specifications_doc) diff --git a/SAS/TMSS/backend/test/tmss_test_data_django_models.py b/SAS/TMSS/backend/test/tmss_test_data_django_models.py index 43aefbbb0e6ecad738ded5425a2ce3190423db86..82d20fc3cd119de455df7d9d2f25e8a98694a933 100644 --- a/SAS/TMSS/backend/test/tmss_test_data_django_models.py +++ b/SAS/TMSS/backend/test/tmss_test_data_django_models.py @@ -275,7 +275,9 @@ def SchedulingUnitBlueprint_test_data(name=None, specifications_template: models specifications_template = models.SchedulingUnitTemplate.objects.create(**SchedulingUnitTemplate_test_data()) if draft is None: - draft = models.SchedulingUnitDraft.objects.create(**SchedulingUnitDraft_test_data(name=name, scheduling_constraints_template=scheduling_constraints_template)) + draft = models.SchedulingUnitDraft.objects.create(**SchedulingUnitDraft_test_data(name=name, + template=specifications_template, + scheduling_constraints_template=scheduling_constraints_template)) if output_pinned is None: output_pinned = False