Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ and this project adheres to

### Fixed

- The workflows REST API now returns a 422 validation error instead of a 500
when a create request omits `edges`, `jobs`, or `triggers` from the body
rather than sending them as empty lists.
[#4982](https://github.com/OpenFn/lightning/issues/4982)
- Sandbox merge no longer deletes a workflow that was added to the project after
the sandbox was branched. Such workflows were never part of the sandbox, so
they are excluded from the merge screen entirely. Workflows deleted inside the
Expand Down
8 changes: 8 additions & 0 deletions lib/lightning_web/controllers/api/workflows_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ defmodule LightningWeb.API.WorkflowsController do
),
do: validate_workflow(edges, jobs, triggers, ids_map)

defp validate_workflow(%{} = params, ids_map) do
edges = Map.get(params, "edges", [])
jobs = Map.get(params, "jobs", [])
triggers = Map.get(params, "triggers", [])

validate_workflow(edges, jobs, triggers, ids_map)
end

defp validate_workflow(edges, jobs, triggers, ids_map) do
# {:ok, _ids} <- validate_ids(edges),
with {:ok, triggers_ids} <- validate_ids(triggers),
Expand Down
19 changes: 19 additions & 0 deletions test/lightning_web/controllers/api/workflows_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,25 @@ defmodule LightningWeb.API.WorkflowsControllerTest do
}
end

test "returns 422 when edges, jobs and triggers are omitted", %{
conn: conn,
project: project
} do
conn =
post(
conn,
~p"/api/projects/#{project.id}/workflows",
Jason.encode!(%{name: "workflow without children"})
)

assert json_response(conn, 422) == %{
"id" => nil,
"errors" => %{
"edges" => ["Missing edge with source_trigger_id."]
}
}
end

test "returns 422 when edges has multiple source triggers", %{
conn: conn,
project: project
Expand Down