spacebat

spacebat

`string_join` expression failing when first argument is not a literal list of strings

I have a resource with an attribute that is an array of strings. Calculations on these arrays seem inconsistent:

  attribute :tags, {:array, :string}, allow_nil?: false

Some calculations:

  calculate :num_tags, :integer, expr(length(tags))
  calculate :all_tags, :string, expr(string_join(tags, ", "))
  calculate :reverse_tags, {:array, :string}, expr(lazy({__MODULE__, :reverse, [tags]}))

Loading :num_tags works, but loading :all_tags raises:
(Protocol.UndefinedError) protocol Enumerable not implemented for drivers of type Ash.Query.Ref (a struct)
If I substitute a literal list of strings the expression works.
When I include the third calculation it fails to compile, undefined variable “tags”, but if I wrap it to be [expr(tags)] then it compiled but I’m back to the Protocol.UndefinedError above, and yet it works with a literal list of strings.
It looks like some calculations on compound attributes don’t work. I’m using ash 2.21.12 and ash_postgres 1.5.23.

Most Liked

zachdaniel

zachdaniel

Creator of Ash

I’ve pushed a fix for the string_join calculation only working with literal values to both the latest 3.0 release candidate and the 2.0 branch.
We’ll need to look into the lazy separately, since I’m not quite sure how related or unrelated to this issue it is. Lets start a new GH issue or thread if you still have issues after upgrading.

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement