How can “one” control the order of the arguments created for the functions defined via the code_interface (in the domain)?
My action in the resource has 2 “accepts” and 3 more non-nullable arguments.
Consequently, the define in the domain module has 5 args (in my preferred order).
However, when I look at the call interface of the generated function using h in IEx, the order is different, How can I control/influence this to best fit my intended use?
Thanks
Martin
Arguments will be first and in order defined. then you can add action input as map.
From docs:
They will also have an optional second to last argument that is a freeform map to provide action input. It must be a map . If it is a keyword list, it will be assumed that it is actually options
(for convenience). This allows for the following behaviour:
# When all arguments are provided it is unambiguous
Accounts.register_user(username, password, %{key: "val"}, [tenant: "organization_22"])
So accept params should go into the free form map at the end (before options) I believe.
1 Like
The order should definitely not be different than your defined list. If it is then it’s a bug.
2 Likes
So it appears that it could be a bug (in - I assume - Ash.CodeInterface.define_interface. Possible related to creating a Map from the original list of args.
In my case, I have args: [:a, :b, :c, :d, :e,] being fed to an action that has:
accepts [:a, :b]
…and…
4 arguments in the order :c, :e, :d + another (used by a change)
The order is the generated function is:
:b, :a, :c, :d, :e
In other words :a & :b are switched
My only thought is that I wonder if it is relevant that :b is the generated id for a belongs_to relationship and :a is a regular string attribute on the resource.
I tried to read the Ash source to get a sense of the processing - but it is a bit long!
Thanks
Martin
can you show me how you know the order of the args is incorrect? Are you seeing that by calling it? Or looking at the generated docs?
The code in the domain contains:
resource Flow.Model.Warehouse do
define :create_warehouse_with_pool,
action: :create_with_pool,
args: [
:world_id,
:name,
:pool_name,
:pool_type,
:volume
]
… etc
In IEx when I type h Model.create_warehouse_with_pool, I see:
def create_warehouse_with_pool(world_id, name, pool_name, pool_type, volume, params \ nil, opts \ nil)
Calls the create_with_pool action on Flow.Model.Warehouse.
Arguments
• name
• world_id
• pool_name
• pool_type
• volume
Inputs
• pool
So… world_id and name are switched.
Martin
Got it
That is a different thing. That is just the bullet list documentation of arguments being switched. Lower priority but should still be fixed. The actual function arguments are in the right order.
def create_warehouse_with_pool(world_id, name, pool_name, pool_type, volume, params \ nil, opts \ nil)
Can you open an issue on ash
to have it fixed?
Will do. Thanks for pointing out that is was just the documentation that was wonky. I hadn’t spotted that (clearly)!
1 Like