From b38bdbf2d2d06e11bb7585898defe248c8edce65 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 18 Apr 2025 13:17:18 -0400 Subject: [PATCH] 21074: Only apply strict validation to linked workflow collections If you have a collection of type: workflow, strict validation only applies if it is actually linked. This accomodates legacy collections which have type: workflow but don't have all the newly defined fields. Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- services/api/app/models/collection.rb | 7 +++-- .../api/test/integration/workflows_test.rb | 28 ++++++++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb index a990d27b59..ce6bb34dfd 100644 --- a/services/api/app/models/collection.rb +++ b/services/api/app/models/collection.rb @@ -616,9 +616,10 @@ class Collection < ArvadosModel # "workflow_type_property" validation and can't be changed or removed as # long as there are linked workflows # - # - "workflows" is provided by the ActiveRecord association at - # the top of the file - if !new_record? && properties["type"] == "workflow" + # - "workflows" is provided by the ActiveRecord association at the + # top of the file, we only want to do this (including + # enforcement of property contents) if the collection is linked. + if !new_record? && properties["type"] == "workflow" && workflows.any? update_linked_workflows(workflows, true) end end diff --git a/services/api/test/integration/workflows_test.rb b/services/api/test/integration/workflows_test.rb index b9f05c462c..3785f54e83 100644 --- a/services/api/test/integration/workflows_test.rb +++ b/services/api/test/integration/workflows_test.rb @@ -232,6 +232,10 @@ class WorkflowsApiTest < ActionDispatch::IntegrationTest end test "collection is missing cwl_inputs" do + # The following is allowed, because it isn't linked. + # This is what legacy arvados-cwl-runner instances + # have been creating, so we want to make sure we can still + # create them, but not link them. post "/arvados/v1/collections", params: {:format => :json, collection: { @@ -239,12 +243,23 @@ class WorkflowsApiTest < ActionDispatch::IntegrationTest description: "the workflow that tests linking collection and workflow records", properties: { "type": "workflow", - "arv:workflowMain": "foo.cwl" + "arv:workflowMain": "foo.cwl" } } }, headers: auth(:active), as: :json + assert_response :success + collection_response = json_response + + # But it can't be linked because it doesn't have all the fields + post "/arvados/v1/workflows", + params: {:format => :json, + :workflow => { + collection_uuid: collection_response["uuid"] + } + }, + headers: auth(:active) assert_response 422 assert_match(/missing field 'arv:cwl_inputs' in collection properties/, json_response["errors"][0]) end @@ -276,6 +291,17 @@ class WorkflowsApiTest < ActionDispatch::IntegrationTest }, headers: auth(:active), as: :json + assert_response :success + collection_response = json_response + + # But it can't be linked because one of the fields is invalid + post "/arvados/v1/workflows", + params: {:format => :json, + :workflow => { + collection_uuid: collection_response["uuid"] + } + }, + headers: auth(:active) assert_response 422 assert_match(/expected field 'arv:cwl_inputs' in collection properties to be a Array/, json_response["errors"][0]) end -- 2.39.5