chore: a few small error case improvements

This commit is contained in:
Zach Daniel 2023-04-01 18:19:08 -04:00
parent f832ab3624
commit eb2c2de528
4 changed files with 19 additions and 4 deletions

View file

@ -31,7 +31,17 @@ defmodule Ash.CodeInterface do
{:argument, argument} {:argument, argument}
end end
if !field.allow_nil? do cond do
field.allow_nil? && !(field.name in Map.get(action, :require_attributes, [])) ->
:ok
field.name in Map.get(action, :allow_nil_input, []) ->
:ok
!(field.name in Map.get(action, :accept, [])) ->
:ok
true ->
raise "Code interface for #{action.name} has optional argument #{key} but it is not optional" raise "Code interface for #{action.name} has optional argument #{key} but it is not optional"
end end

View file

@ -255,6 +255,7 @@ defmodule Ash.Engine do
def must_be_local?(request) do def must_be_local?(request) do
[request.resource | request.touches_resources || []] [request.resource | request.touches_resources || []]
|> Enum.filter(& &1) |> Enum.filter(& &1)
|> Enum.filter(&is_atom/1)
|> Enum.any?(fn resource -> |> Enum.any?(fn resource ->
(Ash.DataLayer.data_layer_can?(resource, :transact) && (Ash.DataLayer.data_layer_can?(resource, :transact) &&
Ash.DataLayer.in_transaction?(resource)) || Ash.DataLayer.in_transaction?(resource)) ||

View file

@ -113,6 +113,10 @@ defmodule Ash.Resource do
end end
if api = Ash.Resource.Info.define_interface_for(__MODULE__) do if api = Ash.Resource.Info.define_interface_for(__MODULE__) do
if api == __MODULE__ do
raise "code_interface.define_for should be set to the API module you want it to call, not the resource."
end
require Ash.CodeInterface require Ash.CodeInterface
Ash.CodeInterface.define_interface(api, __MODULE__) Ash.CodeInterface.define_interface(api, __MODULE__)
end end

View file

@ -8,11 +8,11 @@ defmodule Ash.Resource.Interface do
defmacro __using__(_) do defmacro __using__(_) do
quote bind_quoted: [], generated: true do quote bind_quoted: [], generated: true do
if Ash.Resource.Info.define_interface_for(__MODULE__) do if define_for = Ash.Resource.Info.define_interface_for(__MODULE__) do
require Ash.CodeInterface require Ash.CodeInterface
Ash.CodeInterface.define_interface( Ash.CodeInterface.define_interface(
Ash.Resource.Info.define_interface_for(__MODULE__), define_for,
__MODULE__ __MODULE__
) )
end end