Supports callback in Ash Validations

Is the supports/1 callback for the validation behaviour no longer available in Ash? Copied and pasted this email validation example from the Ash docs https://hexdocs.pm/ash/validations.html#supporting-queries-in-custom-validations
defmodule MyApp.Validations.Email do
use Ash.Resource.Validation

@impl true
def init(opts) do
{:ok, opts}
end

@impl true
def supports(_opts), do: [Ash.Changeset, Ash.Query]

@impl true
def validate(subject, opts, _context) do
value = get_value(subject, opts[:attribute])

if is_nil(value) || valid_email?(value) do
:ok
else
{:error, field: opts[:attribute], message: "must be a valid email"}
end
end

defp get_value(%Ash.Changeset{} = changeset, attribute) do
Ash.Changeset.get_argument_or_attribute(changeset, attribute)
end

defp get_value(%Ash.Query{} = query, attribute) do
Ash.Query.get_argument(query, attribute)
end

defp valid_email?(email) do
String.match?(email, ~r/^[^\s]+@[^\s]+\.[^\s]+$/)
end
end
defmodule MyApp.Validations.Email do
use Ash.Resource.Validation

@impl true
def init(opts) do
{:ok, opts}
end

@impl true
def supports(_opts), do: [Ash.Changeset, Ash.Query]

@impl true
def validate(subject, opts, _context) do
value = get_value(subject, opts[:attribute])

if is_nil(value) || valid_email?(value) do
:ok
else
{:error, field: opts[:attribute], message: "must be a valid email"}
end
end

defp get_value(%Ash.Changeset{} = changeset, attribute) do
Ash.Changeset.get_argument_or_attribute(changeset, attribute)
end

defp get_value(%Ash.Query{} = query, attribute) do
Ash.Query.get_argument(query, attribute)
end

defp valid_email?(email) do
String.match?(email, ~r/^[^\s]+@[^\s]+\.[^\s]+$/)
end
end
but I'm getting this error:
got "@impl true" for function supports/1 but no behaviour specifies such callback. The known callbacks are:

* Ash.Resource.Validation.atomic/3 (function)
* Ash.Resource.Validation.atomic?/0 (function)
* Ash.Resource.Validation.describe/1 (function)
* Ash.Resource.Validation.has_validate?/0 (function)
* Ash.Resource.Validation.init/1 (function)
* Ash.Resource.Validation.validate/3 (function)
Elixir
got "@impl true" for function supports/1 but no behaviour specifies such callback. The known callbacks are:

* Ash.Resource.Validation.atomic/3 (function)
* Ash.Resource.Validation.atomic?/0 (function)
* Ash.Resource.Validation.describe/1 (function)
* Ash.Resource.Validation.has_validate?/0 (function)
* Ash.Resource.Validation.init/1 (function)
* Ash.Resource.Validation.validate/3 (function)
Elixir
Solution:
Latest version of Ash only.
Jump to solution
3 Replies
ZachDaniel
ZachDaniel3mo ago
It's brand new
Solution
ZachDaniel
ZachDaniel3mo ago
Latest version of Ash only.
Joan Gavelán
Joan GavelánOP3mo ago
Oh nice, just upgraded and it's working. thanks

Did you find this page helpful?