mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
fix: set flow argument defaults
This commit is contained in:
parent
fbc341b3a0
commit
fbd2b2f50c
3 changed files with 31 additions and 8 deletions
|
@ -408,7 +408,7 @@ defmodule Ash.DataLayer.Mnesia do
|
|||
@doc false
|
||||
@impl true
|
||||
def transaction(_, func, _timeout, _reason) do
|
||||
case Mnesia.transaction(func) do
|
||||
case Mnesia.transaction(func, 1) do
|
||||
{:atomic, result} ->
|
||||
{:ok, result}
|
||||
|
||||
|
|
|
@ -168,12 +168,37 @@ defmodule Ash.Flow do
|
|||
defp cast_input(flow, params) do
|
||||
arguments = Ash.Flow.Info.arguments(flow)
|
||||
|
||||
Enum.reduce_while(params, {:ok, %{}}, fn {name, value}, {:ok, acc} ->
|
||||
case Enum.find(arguments, &(&1.name == name || to_string(&1.name) == name)) do
|
||||
nil ->
|
||||
{:cont, {:ok, acc}}
|
||||
Enum.reduce_while(arguments, {:ok, %{}}, fn arg, {:ok, acc} ->
|
||||
value =
|
||||
case Map.fetch(params, arg.name) do
|
||||
:error ->
|
||||
Map.fetch(params, to_string(arg.name))
|
||||
|
||||
arg ->
|
||||
other ->
|
||||
other
|
||||
end
|
||||
|
||||
case value do
|
||||
:error ->
|
||||
if not is_nil(arg.default) do
|
||||
value =
|
||||
case arg.default do
|
||||
{m, f, a} ->
|
||||
apply(m, f, a)
|
||||
|
||||
fun when is_function(fun, 0) ->
|
||||
fun.()
|
||||
|
||||
value ->
|
||||
value
|
||||
end
|
||||
|
||||
{:cont, {:ok, Map.put(acc, arg.name, value)}}
|
||||
else
|
||||
{:cont, {:ok, acc}}
|
||||
end
|
||||
|
||||
{:ok, value} ->
|
||||
with {:ok, value} <-
|
||||
Ash.Type.Helpers.cast_input(arg.type, value, arg.constraints, flow),
|
||||
{:constrained, {:ok, casted}}
|
||||
|
|
|
@ -4,9 +4,7 @@ defmodule Ash.Test.Flow.Flows.Halting do
|
|||
|
||||
flow do
|
||||
argument :on_step, :atom do
|
||||
allow_nil? false
|
||||
constraints one_of: [:a, :b, :c]
|
||||
default :a
|
||||
end
|
||||
|
||||
returns :c
|
||||
|
|
Loading…
Reference in a new issue