Skip to content

Commit

Permalink
Merge pull request #1049 from OpenFn/fix-save-and-run-crash
Browse files Browse the repository at this point in the history
Fix app crashing when one saves a job then runs it
  • Loading branch information
taylordowns2000 authored Aug 25, 2023
2 parents 482c35d + 8d1d766 commit 20f9422
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 8 additions & 0 deletions lib/lightning_web/live/job_live/manual_run_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ defmodule LightningWeb.JobLive.ManualRunComponent do
|> put_embed(:job, job)
|> put_embed(:user, user)
|> validate_required([:project, :job, :user])
|> remove_body_if_dataclip_present()
|> Lightning.Validators.validate_exclusive(
[:dataclip_id, :body],
"Dataclip and custom body are mutually exclusive."
Expand All @@ -31,6 +32,13 @@ defmodule LightningWeb.JobLive.ManualRunComponent do
"Either a dataclip or a custom body must be present."
)
end

defp remove_body_if_dataclip_present(changeset) do
case get_change(changeset, :dataclip_id) do
nil -> changeset
_ -> Ecto.Changeset.delete_change(changeset, :body)
end
end
end

alias LightningWeb.Components.Form
Expand Down
7 changes: 0 additions & 7 deletions lib/lightning_web/live/workflow_live/edit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ defmodule LightningWeb.WorkflowLive.Edit do
{:ok, workflow} ->
socket
|> assign_workflow(workflow)
|> push_patch(to: build_next_path(socket, workflow), replace: true)
|> put_flash(:info, "Workflow saved")

{:error, changeset} ->
Expand Down Expand Up @@ -709,12 +708,6 @@ defmodule LightningWeb.WorkflowLive.Edit do
end
end

defp build_next_path(socket, workflow) do
%{project: project, selection_params: selection_params} = socket.assigns

~p"/projects/#{project}/w/#{workflow}?#{selection_params |> Map.reject(&match?({_, nil}, &1))}"
end

# find the changeset for the selected item
# it could be an edge, a job or a trigger
defp find_item_in_changeset(changeset, id) do
Expand Down

0 comments on commit 20f9422

Please sign in to comment.