If I set an argument default in a Flow I have it `nil` in a custom step

defmodule MmsBiztalk.Flows.Rollback do
use Ash.Flow

flow do
api MmsBiztalk

argument :resource, :string do
allow_nil? false
end

argument :step, :integer do
default 1
end

argument :resource_id, :integer

returns :get_last_data_in_resources
end

steps do
custom :get_last_data_in_resources, MmsBiztalk.Flows.Steps.LastDataInResources do
input %{resource: arg(:resource), resource_id: arg(:resource_id)}
end

transaction :back_in_time, MmsBiztalk.DataIn do
map :cycle_resources_changes, result(:get_last_data_in_resources) do
custom :rollback_resource, MmsBiztalk.Flows.Steps.RollbackResource do
input %{
resource: arg(:resource),
change: element(:cycle_resources_changes),
step: arg(:step)
}
end
end
end
end
end
defmodule MmsBiztalk.Flows.Rollback do
use Ash.Flow

flow do
api MmsBiztalk

argument :resource, :string do
allow_nil? false
end

argument :step, :integer do
default 1
end

argument :resource_id, :integer

returns :get_last_data_in_resources
end

steps do
custom :get_last_data_in_resources, MmsBiztalk.Flows.Steps.LastDataInResources do
input %{resource: arg(:resource), resource_id: arg(:resource_id)}
end

transaction :back_in_time, MmsBiztalk.DataIn do
map :cycle_resources_changes, result(:get_last_data_in_resources) do
custom :rollback_resource, MmsBiztalk.Flows.Steps.RollbackResource do
input %{
resource: arg(:resource),
change: element(:cycle_resources_changes),
step: arg(:step)
}
end
end
end
end
end
in MmsBiztalk.Flows.Steps.RollbackResource the value of input.step is nil.
13 Replies
ZachDaniel
ZachDaniel3y ago
So it’s not setting default values?
tommasop#2001
tommasop#2001OP3y ago
Exactly
ZachDaniel
ZachDaniel3y ago
fixed in main 🙂
tommasop#2001
tommasop#2001OP3y ago
Working thanks a lot @Zach Daniel it now seems if I set the value it will still get the default .... 😅
ZachDaniel
ZachDaniel3y ago
Wait really? Does it happen only if you set the value to nil?
tommasop#2001
tommasop#2001OP3y ago
the actual case is with the default value to nil?
ZachDaniel
ZachDaniel3y ago
sorry, not following
tommasop#2001
tommasop#2001OP3y ago
argument :update_key, :atom do
default nil
end

argument :status_changes, :term do
default nil
end

returns :create_data_in_and_map_resources
end

steps do
transaction :create_data_in_and_map_resources, MmsBiztalk.DataIn do
create :create_data_in, MmsBiztalk.DataIn, :create do
input %{data_type: arg(:data_type)}
end

map :cycle_resources, arg(:resources_attributes) do
branch :creation_bulk, expr(is_nil(^arg(:update_key))) do
custom :create_resource, MmsBiztalk.Flows.Steps.CreateResource do
input %{
attributes: element(:cycle_resources),
resource: arg(:resource),
data_in_id: path(result(:create_data_in), [:id])
}
end
argument :update_key, :atom do
default nil
end

argument :status_changes, :term do
default nil
end

returns :create_data_in_and_map_resources
end

steps do
transaction :create_data_in_and_map_resources, MmsBiztalk.DataIn do
create :create_data_in, MmsBiztalk.DataIn, :create do
input %{data_type: arg(:data_type)}
end

map :cycle_resources, arg(:resources_attributes) do
branch :creation_bulk, expr(is_nil(^arg(:update_key))) do
custom :create_resource, MmsBiztalk.Flows.Steps.CreateResource do
input %{
attributes: element(:cycle_resources),
resource: arg(:resource),
data_in_id: path(result(:create_data_in), [:id])
}
end
the argument update_key even if has a value is always nil
ZachDaniel
ZachDaniel3y ago
🥲
ZachDaniel
ZachDaniel3y ago
I don’t really see how that would happen here: https://github.com/ash-project/ash/blob/main/lib/ash/flow/flow.ex#L168
GitHub
ash/flow.ex at main · ash-project/ash
A declarative and extensible framework for building Elixir applications. - ash/flow.ex at main · ash-project/ash
tommasop#2001
tommasop#2001OP3y ago
No description
tommasop#2001
tommasop#2001OP3y ago
Sorry my bad, the problem is how to pass parameters to flows it seems after some number of parameters the arguments must go in a map I can pass parameters normally up to three (don't know why)
MmsBiztalk.Flows.EsolverToBiztalk.BulkPull.run("one", "two", "three")
MmsBiztalk.Flows.EsolverToBiztalk.BulkPull.run("one", "two", "three")
after the third I need to pass them in maps:
MmsBiztalk.Flows.EsolverToBiztalk.BulkPull.run("one", "two", "three", %{four: "four", five: "five"})
MmsBiztalk.Flows.EsolverToBiztalk.BulkPull.run("one", "two", "three", %{four: "four", five: "five"})
ZachDaniel
ZachDaniel3y ago
ah, its only params that don't have defaults that are automatically added as arguments Sorry, it’s “params that are required that don’t have a default” it’s a bit magical, probably should have just made them all passed as a map TBH

Did you find this page helpful?