Browse Source

HUE-8232 [oozie] Fix 500 error if coordinator associated workflow has been deleted

Ying Chen 7 years ago
parent
commit
29af0b9ccd

+ 4 - 0
apps/oozie/src/oozie/static/oozie/js/coordinator-editor.ko.js

@@ -84,10 +84,14 @@ var CoordinatorEditorViewModel = (function () {
     }
 
     self.refreshParameters = function() {
+      if (!self.properties.workflow()) { return; }
+
       $.get("/oozie/editor/workflow/parameters/", {
         "uuid": self.properties.workflow(),
         "document": self.properties.document(),
       }, function (data) {
+        if (data.status < 0) { return; }
+
         self.workflowParameters(data.parameters);
 
         // Remove Uncommon params

+ 1 - 1
apps/oozie/src/oozie/templates/editor2/common_scheduler.inc.mako

@@ -39,7 +39,7 @@ from django.utils.translation import ugettext as _
 
         <div class="card-body">
           <a class="pointer" data-bind="visible: ! coordinator.properties.workflow(), click: showChooseWorkflow">${ _('Choose a workflow...') }</a>
-          <!-- ko if: coordinator.properties.workflow -->
+          <!-- ko if: getWorkflowById(coordinator.properties.workflow()) -->
             <!-- ko if: isEditing -->
             <a class="pointer" data-bind="click: showChooseWorkflow, text: getWorkflowById(coordinator.properties.workflow()).name"></a>
 

+ 11 - 2
apps/oozie/src/oozie/views/editor2.py

@@ -504,8 +504,17 @@ def edit_coordinator(request):
   if USE_NEW_EDITOR.get():
     scheduled_uuid = coordinator.data['properties']['workflow'] or coordinator.data['properties']['document']
     if scheduled_uuid:
-      document = Document2.objects.get(uuid=scheduled_uuid)
-      if not document.can_read(request.user):
+      try:
+        document = Document2.objects.get(uuid=scheduled_uuid)
+      except Document2.DoesNotExist as e:
+        document = None
+        coordinator.data['properties']['workflow'] = ''
+        LOG.warn("Workflow with uuid %s doesn't exist: %s" % (scheduled_uuid, e))
+
+      if document and document.is_trashed:
+        raise PopupException(_('Your workflow %s has been trashed!') % (document.name if document.name else ''))
+
+      if document and not document.can_read(request.user):
         raise PopupException(_('You don\'t have access to the workflow or document of this coordinator.'))
   else:
     workflows = [dict([('uuid', d.content_object.uuid), ('name', d.content_object.name)])