From 739ba7d9fb68b40dda0f3694f6fcd97858db85b8 Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Thu, 25 Feb 2021 11:46:20 +0100
Subject: [PATCH] TMSS-652: do not import at top of file before django is
 configured

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

diff --git a/SAS/TMSS/backend/services/tmss_postgres_listener/lib/tmss_postgres_listener.py b/SAS/TMSS/backend/services/tmss_postgres_listener/lib/tmss_postgres_listener.py
index 6ed29be0f7a..93e5c5a7f11 100644
--- a/SAS/TMSS/backend/services/tmss_postgres_listener/lib/tmss_postgres_listener.py
+++ b/SAS/TMSS/backend/services/tmss_postgres_listener/lib/tmss_postgres_listener.py
@@ -28,7 +28,6 @@ from lofar.messaging.messagebus import ToBus
 from lofar.sas.tmss.client.tmssbuslistener import *
 from lofar.common import dbcredentials
 from lofar.common.util import single_line_with_single_spaces
-from lofar.sas.tmss.tmss.tmssapp.models import Subtask, SchedulingUnitBlueprint, TaskBlueprint
 from distutils.util import strtobool
 
 
@@ -177,6 +176,7 @@ class TMSSPGListener(PostgresListener):
     def onSubTaskStateUpdated(self, payload = None):
         payload_dict = json.loads(payload)
         # send notification for this subtask...
+        from lofar.sas.tmss.tmss.tmssapp.models import Subtask
         subtask = Subtask.objects.get(id=payload_dict['id'])
         self._sendNotification(TMSS_SUBTASK_STATUS_EVENT_PREFIX+'.'+subtask.state.value.capitalize(),
                                {'id': subtask.id, 'status': subtask.state.value})
@@ -207,6 +207,8 @@ class TMSSPGListener(PostgresListener):
 
         if isinstance(payload, str):
             payload = json.loads(payload)
+
+        from lofar.sas.tmss.tmss.tmssapp.models import TaskBlueprint
         task_blueprint = TaskBlueprint.objects.get(id=payload['id'])
         self._sendNotification(TMSS_SCHEDULINGUNITBLUEPRINT_OBJECT_EVENT_PREFIX+'.Updated', {'id': task_blueprint.scheduling_unit_blueprint.id})
 
@@ -227,6 +229,8 @@ class TMSSPGListener(PostgresListener):
 
         if isinstance(payload, str):
             payload = json.loads(payload)
+
+        from lofar.sas.tmss.tmss.tmssapp.models import SchedulingUnitBlueprint
         scheduling_unit_blueprint = SchedulingUnitBlueprint.objects.get(id=payload['id'])
 
         if not scheduling_unit_blueprint.can_proceed:
-- 
GitLab