Hi, all
Here’s an extract of a union in my codebase:
defmodule Condition do
use Ash.Type.NewType, subtype_of: :union, constraints: [types: [
{Always, [type: Always]},
{ResponseEquals, [type: ResponseEquals, tag: :type, tag_value: "response_equals"]},
{AnyTrue, [type: AnyTrue, tag: :type, tag_value: "any_true"]},
{AllTrue, [type: AllTrue, tag: :type, tag_value: "all_true"]},
]]
end
Upgrading to 3.1 causes this union to throw a compile error:
** (UndefinedFunctionError) function AnyTrue.init/1 is undefined (function not available)
AnyTrue.init([])
(ash 3.1.0) lib/ash/type/union.ex:72: anonymous fn/2 in Ash.Type.Union.init/1
(elixir 1.17.2) lib/enum.ex:4858: Enumerable.List.reduce/3
(elixir 1.17.2) lib/enum.ex:2585: Enum.reduce_while/3
(ash 3.1.0) lib/ash/type/union.ex:68: Ash.Type.Union.init/1
(ash 3.1.0) lib/ash/type/type.ex:627: Ash.Type.init/2
(ash 3.1.0) lib/ash/type/type.ex:1735: Ash.Type.set_type_transformation/1
(spark 2.2.8) lib/spark/dsl/entity.ex:265: Spark.Dsl.Entity.build/3
Only AnyTrue
and AllTrue
are affected and both of them are recursive on Condition
as such:
defmodule AnyTrue do
use Ash.Resource, data_layer: :embedded
attributes do
attribute :conditions, {:array, Condition}, allow_nil?: false, public?: true, constraints: [min_length: 1]
end
end
Is this a bug or a feature in 3.1
? Is there a way around it?