From bc7701d45cbb538160fd8f9f08272f955e809a89 Mon Sep 17 00:00:00 2001
From: Fabio Roberto Vitello <fabio.vitello@inaf.it>
Date: Tue, 1 Sep 2020 19:18:20 +0200
Subject: [PATCH] TMSS-234: Fix on specification and create copy of task draft

- Added a try block to intercept ValueError in RelationalHyperlinkedModelSerializer.get_field_names (it was causing an error that doesn't allow to use  swagger)
- copy_scheduling_unit_draft now create a copy of the original task drafts instead of setting the originals
---
 SAS/TMSS/src/tmss/tmssapp/serializers/specification.py | 5 ++++-
 SAS/TMSS/src/tmss/tmssapp/tasks.py                     | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py
index abe99626f95..9cfe925f96a 100644
--- a/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py
+++ b/SAS/TMSS/src/tmss/tmssapp/serializers/specification.py
@@ -16,7 +16,10 @@ class RelationalHyperlinkedModelSerializer(serializers.HyperlinkedModelSerialize
 
     def get_field_names(self, declared_fields, info):
         field_names = super().get_field_names(declared_fields, info)
-        field_names.remove(self.url_field_name) # is added later, see retun statement
+        try:
+            field_names.remove(self.url_field_name) # is added later, see retun statement
+        except ValueError:
+            pass
 
         if getattr(self.Meta, 'extra_fields', None):
             field_names += self.Meta.extra_fields
diff --git a/SAS/TMSS/src/tmss/tmssapp/tasks.py b/SAS/TMSS/src/tmss/tmssapp/tasks.py
index 70642135c4f..b143f3e0646 100644
--- a/SAS/TMSS/src/tmss/tmssapp/tasks.py
+++ b/SAS/TMSS/src/tmss/tmssapp/tasks.py
@@ -49,8 +49,11 @@ def copy_scheduling_unit_draft(scheduling_unit_draft: models.SchedulingUnitDraft
 
     scheduling_unit_draft_copy.scheduling_set=scheduling_set_dst
 
+    task_drafts_copy = []
     scheduling_unit_draft_copy.save()
-    scheduling_unit_draft_copy.task_drafts.set(task_drafts)
+    for td in task_drafts:
+        task_drafts_copy.append(copy_task_draft(td))
+    scheduling_unit_draft_copy.task_drafts.set(task_drafts_copy)
     scheduling_unit_draft_copy.scheduling_unit_blueprints.set(scheduling_unit_blueprints)
     scheduling_unit_draft_copy.save()
 
-- 
GitLab