Return 422 instead of 500 when workflow create body omits edges, jobs, or triggers - #4985
Return 422 instead of 500 when workflow create body omits edges, jobs, or triggers#4985SAY-5 wants to merge 1 commit into
Conversation
…, or triggers Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
Hey @SAY-5, thank you so much for contributing to fix this issue. Can you please make sure to check the box about AI usage? We don't mind if people use AI, we just want to know |
|
The failing lint job is pre-existing repo-wide drift, not this diff: it's credo --strict flagging TODO tags in core_components.ex/tokens.ex/bootstrap.ex etc plus deps.audit/hex.audit on the lockfile. compile, dialyzer and test_elixir (including the new 422 regression test) are all green on this branch. |
|
Thanks for the extra context @SAY-5 🙏🏻, but can you please tick a box in the AI Usage section in the PR description? |
lmac-1
left a comment
There was a problem hiding this comment.
Hiya @SAY-5, thank you so much for your contribution! This is a clean, well-scoped fix, and the write-up in the description is accurate. Thanks also for ticking the AI usage box 🙏
You mentioned you couldn't run the suite locally, so I ran it here: 56 tests pass, format and Credo clean. I also checked the regression test actually pins the bug. I've verified that removing your fallback clause reproduces the FunctionClauseError, restoring it goes green.
One thing before this can merge: could you merge the latest main into your branch? There's a conflict in CHANGELOG.md.
Optional while you're there: a test for only one key missing (jobs and triggers present, no edges) that crashed the same way and is probably the more common shape. Happy to add it after merge if you'd rather not.
The lint failure looks like pre-existing repo drift rather than your diff so merging main may clear it.
Approving so you're not blocked by me.
Description
This PR fixes a crash in the workflows REST API.
POST /api/projects/:project_id/workflowsraised an unhandledFunctionClauseError(a 500) instead of a validation error when the request body left outedges,jobs, ortriggersentirely, rather than sending them as empty lists.validate_workflow/2only had a map clause matching when all three keys were present, so a create body missing any of them matched no clause. The update path is unaffected because it builds a changeset first, which always has those fields via schema defaults. Only create validates the raw params map directly.The fix adds a fallback clause that defaults the missing keys to
[]and routes through the existing validation, which already returns a proper 422 ("Missing edge with source_trigger_id.") for a workflow with no edges.Closes #4982
Validation steps
POST /api/projects/:project_id/workflowswith a body of just{"name": "..."}(noedges/jobs/triggers).returns 422 when edges, jobs and triggers are omittedcovers this inworkflows_controller_test.exs.Additional notes for the reviewer
returns 422 when edges misses a source triggercase and the empty-list path was traced by hand to confirm it lands on{:error, :edges_misses_a_trigger}and the existingreply_422. Please run it in CI.AI Usage
Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):
You can read more details in our
Responsible AI Policy
Pre-submission checklist
/reviewwith Claude Code)
(e.g.,
:owner,:admin,:editor,:viewer)