diff --git a/hexa/pipelines/models.py b/hexa/pipelines/models.py index 9f8ebf15b..5be28d766 100644 --- a/hexa/pipelines/models.py +++ b/hexa/pipelines/models.py @@ -256,7 +256,11 @@ def run( trigger_mode=trigger_mode, execution_date=timezone.now(), state=PipelineRunState.QUEUED, - config=self.merge_pipeline_config(config, pipeline_version.config), + config=( + self.merge_pipeline_config(config, pipeline_version.config) + if pipeline_version + else self.config + ), access_token=str(uuid.uuid4()), send_mail_notifications=send_mail_notifications, timeout=timeout, diff --git a/hexa/pipelines/tests/test_views.py b/hexa/pipelines/tests/test_views.py index 3f3035dd7..c39ee5243 100644 --- a/hexa/pipelines/tests/test_views.py +++ b/hexa/pipelines/tests/test_views.py @@ -9,7 +9,7 @@ from hexa.core.test import TestCase from hexa.files.tests.mocks.mockgcp import mock_gcp_storage -from hexa.pipelines.models import Pipeline, PipelineRunTrigger +from hexa.pipelines.models import Pipeline, PipelineRunTrigger, PipelineType from hexa.user_management.models import Feature, FeatureFlag, User from hexa.workspaces.models import ( Workspace, @@ -97,6 +97,28 @@ def test_run_pipeline_not_enabled(self): self.assertEqual(r.status_code, 400) self.assertEqual(r.json(), {"error": "Pipeline has no webhook enabled"}) + def test_run_pipeline_notebook_webhook(self): + pipeline = Pipeline.objects.create( + code="new_pipeline", + name="notebook.ipynb", + workspace=self.WORKSPACE, + type=PipelineType.NOTEBOOK, + notebook_path="notebook.ipynb", + webhook_enabled=True, + ) + pipeline.generate_webhook_token() + + response = self.client.post( + reverse( + "pipelines:run", + args=[pipeline.webhook_token], + ), + content_type="application/json", + ) + self.assertEqual(response.status_code, 200) + self.assertEqual(str(pipeline.last_run.id), response.json()["run_id"]) + self.assertEqual(pipeline.last_run.trigger_mode, PipelineRunTrigger.WEBHOOK) + def test_run_pipeline_valid(self): self.assertEqual(self.PIPELINE.last_run, None) response = self.client.post( diff --git a/hexa/pipelines/views.py b/hexa/pipelines/views.py index ccbb0e3ed..e8865ffee 100644 --- a/hexa/pipelines/views.py +++ b/hexa/pipelines/views.py @@ -20,7 +20,7 @@ from hexa.pipelines.models import Environment from .credentials import PipelinesCredentials -from .models import Pipeline, PipelineRunTrigger, PipelineVersion +from .models import Pipeline, PipelineRunTrigger, PipelineType, PipelineVersion from .queue import environment_sync_queue logger = getLogger(__name__) @@ -126,17 +126,19 @@ def run_pipeline( return JsonResponse({"error": "Pipeline has no webhook enabled"}, status=400) # Get the pipeline version - try: - pipeline_version = pipeline.last_version - if version_id is not None: - pipeline_version = PipelineVersion.objects.get( - pipeline=pipeline, id=version_id - ) - - if pipeline_version is None: - return JsonResponse({"error": "Pipeline has no version"}, status=400) - except PipelineVersion.DoesNotExist: - return JsonResponse({"error": "Pipeline version not found"}, status=404) + pipeline_version = None + if pipeline.type == PipelineType.ZIPFILE: + try: + pipeline_version = pipeline.last_version + if version_id is not None: + pipeline_version = PipelineVersion.objects.get( + pipeline=pipeline, id=version_id + ) + + if pipeline_version is None: + return JsonResponse({"error": "Pipeline has no version"}, status=400) + except PipelineVersion.DoesNotExist: + return JsonResponse({"error": "Pipeline version not found"}, status=404) # Get the data from the request content_type = request.META.get("CONTENT_TYPE")