From 656d2a2fd8a584daf049434afe93a31235d7138b Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 22 Apr 2021 10:28:43 +0200
Subject: [PATCH] TMSS-717: added logging, so we know what the error in which
 template is.

---
 .../backend/src/tmss/tmssapp/models/specification.py   | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
index 31f5ca0a85a..45d6b2f9276 100644
--- a/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
+++ b/SAS/TMSS/backend/src/tmss/tmssapp/models/specification.py
@@ -17,7 +17,7 @@ from django.core.exceptions import ValidationError
 import datetime
 from collections import Counter
 from django.utils.functional import cached_property
-
+from pprint import pformat
 
 #
 # Mixins
@@ -219,7 +219,13 @@ class SchedulingUnitObservingStrategyTemplate(NamedCommon):
 
     def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
         if self.template and self.scheduling_unit_template_id and self.scheduling_unit_template.schema:
-            validate_json_against_schema(self.template, self.scheduling_unit_template.schema)
+            try:
+                validate_json_against_schema(self.template, self.scheduling_unit_template.schema)
+            except Exception as e:
+                # log the error for debugging and re-raise
+                logger.error("Error while validating SchedulingUnitObservingStrategyTemplate name='%s' id='%s' error: %s\ntemplate:\n%s",
+                             self.name, self.id, e, pformat(self.template))
+                raise
 
         super().save(force_insert, force_update, using, update_fields)
 
-- 
GitLab