From f5238674a4a9f08acb744c0068f4c121ee2ddb21 Mon Sep 17 00:00:00 2001 From: Dmitry Maganov Date: Fri, 9 Jun 2023 17:16:15 +0300 Subject: [PATCH] fix: drop proper opts keys when calling api in code interface (#608) --- lib/ash/code_interface.ex | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/ash/code_interface.ex b/lib/ash/code_interface.ex index 8b2491ca..aaf0f866 100644 --- a/lib/ash/code_interface.ex +++ b/lib/ash/code_interface.ex @@ -449,7 +449,7 @@ defmodule Ash.CodeInterface do unquote(api).run_action( action_input, - Keyword.drop(opts, [:actor, :changeset, :tenant, :authorize?, :tracer]) + Keyword.drop(opts, [:input, :actor, :tenant, :authorize?, :tracer]) ) end end @@ -477,7 +477,8 @@ defmodule Ash.CodeInterface do end) action_input = - (opts[:input] || unquote(resource)) + opts[:input] + |> Kernel.||(unquote(resource)) |> Ash.ActionInput.for_action( unquote(action.name), input, @@ -486,7 +487,7 @@ defmodule Ash.CodeInterface do unquote(api).run_action!( action_input, - Keyword.drop(opts, [:actor, :changeset, :authorize?, :tracer]) + Keyword.drop(opts, [:input, :actor, :tenant, :authorize?, :tracer]) ) end end @@ -543,7 +544,14 @@ defmodule Ash.CodeInterface do if unquote(interface.get? || action.get?) do query |> unquote(api).read_one( - Keyword.drop(opts, [:query, :tenant, :authorize?, :actor, :not_found_error?]) + Keyword.drop(opts, [ + :query, + :not_found_error?, + :actor, + :tenant, + :authorize?, + :tracer + ]) ) |> case do {:ok, nil} -> @@ -563,7 +571,7 @@ defmodule Ash.CodeInterface do else unquote(api).read( query, - Keyword.drop(opts, [:query, :tenant, :actor, :authorize?]) + Keyword.drop(opts, [:query, :actor, :tenant, :authorize?, :tracer]) ) end end @@ -621,7 +629,14 @@ defmodule Ash.CodeInterface do if unquote(interface.get? || action.get?) do query |> unquote(api).read_one!( - Keyword.drop(opts, [:query, :tenant, :authorize?, :actor, :not_found_error?]) + Keyword.drop(opts, [ + :query, + :not_found_error?, + :actor, + :tenant, + :authorize?, + :tracer + ]) ) |> case do nil -> @@ -638,7 +653,7 @@ defmodule Ash.CodeInterface do else unquote(api).read!( query, - Keyword.drop(opts, [:query, :tenant, :actor, :authorize?]) + Keyword.drop(opts, [:query, :actor, :tenant, :authorize?, :tracer]) ) end end @@ -677,7 +692,7 @@ defmodule Ash.CodeInterface do unquote(api).create( changeset, - Keyword.drop(opts, [:actor, :changeset, :tenant, :authorize?, :tracer]) + Keyword.drop(opts, [:changeset, :actor, :tenant, :authorize?, :tracer]) ) end end @@ -705,7 +720,8 @@ defmodule Ash.CodeInterface do end) changeset = - (opts[:changeset] || unquote(resource)) + opts[:changeset] + |> Kernel.||(unquote(resource)) |> Ash.Changeset.for_create( unquote(action.name), input, @@ -714,7 +730,7 @@ defmodule Ash.CodeInterface do unquote(api).create!( changeset, - Keyword.drop(opts, [:actor, :changeset, :authorize?, :tracer]) + Keyword.drop(opts, [:changeset, :actor, :tenant, :authorize?, :tracer]) ) end end