diff --git a/lib/ash/actions/create.ex b/lib/ash/actions/create.ex index 5bb4a40c..0d9e3bc2 100644 --- a/lib/ash/actions/create.ex +++ b/lib/ash/actions/create.ex @@ -49,9 +49,13 @@ defmodule Ash.Actions.Create do {:ok, %{data: %{commit: %^resource{} = created}} = engine_result} -> add_notifications(created, engine_result, return_notifications?) - {:error, %Ash.Engine.Runner{errors: errors, changeset: runner_changeset}} -> + {:error, %Ash.Engine.Runner{errors: errors, changeset: %Ash.Changeset{} = runner_changeset}} -> errors = Helpers.process_errors(changeset, errors) - {:error, Ash.Error.to_error_class(errors, changeset: runner_changeset || changeset)} + {:error, Ash.Error.to_error_class(errors, changeset: runner_changeset)} + + {:error, %Ash.Engine.Runner{errors: errors}} -> + errors = Helpers.process_errors(changeset, errors) + {:error, Ash.Error.to_error_class(errors, changeset: changeset)} {:error, error} -> error = Helpers.process_errors(changeset, error) diff --git a/lib/ash/changeset/changeset.ex b/lib/ash/changeset/changeset.ex index 76b96061..72f472df 100644 --- a/lib/ash/changeset/changeset.ex +++ b/lib/ash/changeset/changeset.ex @@ -996,10 +996,13 @@ defmodule Ash.Changeset do [] end + masked_argument_names = Enum.map(action.arguments, & &1.name) + resource |> Ash.Resource.Info.attributes() |> Enum.reject( - &(&1.allow_nil? || &1.private? || !&1.writable? || &1.generated? || &1.name in belongs_to || + &(&1.allow_nil? || &1.private? || !&1.writable? || &1.generated? || + &1.name in masked_argument_names || &1.name in belongs_to || &1.name in allow_nil_input) ) end diff --git a/lib/ash/filter/template_helpers.ex b/lib/ash/filter/template_helpers.ex index a6c7fbc6..f0cf602c 100644 --- a/lib/ash/filter/template_helpers.ex +++ b/lib/ash/filter/template_helpers.ex @@ -7,6 +7,12 @@ defmodule Ash.Filter.TemplateHelpers do @doc "A helper for using action arguments in filter templates" def arg(name), do: {:_arg, name} + @doc "A helper for creating a reference" + def ref(name), do: {:_ref, [], name} + + @doc "A helper for creating a reference to a related path" + def ref(path, name), do: {:_ref, path, name} + @doc """ A helper for using query context in filter templates diff --git a/lib/ash/query/query.ex b/lib/ash/query/query.ex index 0c41be0b..404d22eb 100644 --- a/lib/ash/query/query.ex +++ b/lib/ash/query/query.ex @@ -407,12 +407,6 @@ defmodule Ash.Query do end end - defmacro expr({var, _, context} = binding) when is_atom(var) and is_atom(context) do - quote do - unquote(binding) - end - end - defmacro expr(body) do if Keyword.keyword?(body) do quote do @@ -431,6 +425,14 @@ defmodule Ash.Query do defp do_expr(expr, escape? \\ true) + defp do_expr({op, _, nil}, escape?) when is_atom(op) do + soft_escape(%Ash.Query.Ref{relationship_path: [], attribute: op}, escape?) + end + + defp do_expr({op, _, Elixir}, escape?) when is_atom(op) do + soft_escape(%Ash.Query.Ref{relationship_path: [], attribute: op}, escape?) + end + defp do_expr({:^, _, [value]}, _escape?) do value end @@ -545,10 +547,6 @@ defmodule Ash.Query do end end - defp do_expr({op, _, nil}, escape?) when is_atom(op) do - soft_escape(%Ash.Query.Ref{relationship_path: [], attribute: op}, escape?) - end - defp do_expr({op, _, args}, escape?) when op in [:and, :or] do args = Enum.map(args, &do_expr(&1, false))