AE
Ash Elixir•3w ago
EAJ

Book seed issue: Tunez.Music.Artist.read had no matching bulk strategy that could be used

When I try to run the first seed script for artists from the book code I get the following error message:
** (Ash.Error.Invalid)
Invalid Error

* Tunez.Music.Artist.read had no matching bulk strategy that could be used.

Requested strategies: [:stream]

Could not use `:stream`: could not stream the query
Could not use `:atomic_batches`: Not in requested strategies
Could not use `:atomic`: Not in requested strategies



Non stream reason:

Action Tunez.Music.Artist.read does not support streaming with one of [:keyset].

There are two ways to handle this.

1.) Use the `allow_stream_with` or `stream_with` options to control what strategies are allowed.
2.) Enable the respective required pagination type on the action read, for example:

# allow keyset
pagination keyset?: true, required?: false

# allow offset
pagination offset?: true, required?: false

# allow both
pagination offset?: true, keyset?: true, required?: false
** (Ash.Error.Invalid)
Invalid Error

* Tunez.Music.Artist.read had no matching bulk strategy that could be used.

Requested strategies: [:stream]

Could not use `:stream`: could not stream the query
Could not use `:atomic_batches`: Not in requested strategies
Could not use `:atomic`: Not in requested strategies



Non stream reason:

Action Tunez.Music.Artist.read does not support streaming with one of [:keyset].

There are two ways to handle this.

1.) Use the `allow_stream_with` or `stream_with` options to control what strategies are allowed.
2.) Enable the respective required pagination type on the action read, for example:

# allow keyset
pagination keyset?: true, required?: false

# allow offset
pagination offset?: true, required?: false

# allow both
pagination offset?: true, keyset?: true, required?: false
This is my Artist resource. I've tried to follow the book, but might have messed something up.
defmodule Tunez.Music.Artist do
use Ash.Resource, otp_app: :tunez, domain: Tunez.Music, data_layer: AshPostgres.DataLayer

postgres do
table "artists"
repo Tunez.Repo
end

actions do
create :create do
accept [:name, :biography]
end

read :read do
primary? true
end

update :update do
accept [:name, :biography]
end

destroy :destroy do
end
end

attributes do
uuid_primary_key :id

attribute :name, :string do
allow_nil? false
end

attribute :biography, :string

create_timestamp :inserted_at
update_timestamp :updated_at
end

relationships do
has_many :albums, Tunez.Music.Album
end
end
defmodule Tunez.Music.Artist do
use Ash.Resource, otp_app: :tunez, domain: Tunez.Music, data_layer: AshPostgres.DataLayer

postgres do
table "artists"
repo Tunez.Repo
end

actions do
create :create do
accept [:name, :biography]
end

read :read do
primary? true
end

update :update do
accept [:name, :biography]
end

destroy :destroy do
end
end

attributes do
uuid_primary_key :id

attribute :name, :string do
allow_nil? false
end

attribute :biography, :string

create_timestamp :inserted_at
update_timestamp :updated_at
end

relationships do
has_many :albums, Tunez.Music.Album
end
end
I am using the unmodified seed script from the code repo: https://github.com/sevenseacat/tunez/blob/main/priv/repo/seeds/01-artists.exs If I remove strategy: :stream from Ash.bulk_destroy! it works.
GitHub
tunez/priv/repo/seeds/01-artists.exs at main · sevenseacat/tunez
The starter application for the Ash Framework book - sevenseacat/tunez
4 Replies
EAJ
EAJOP•3w ago
As a side note, when cloning the repository and checking out the end-of-chapter-2 branch the seed script works fine, so it looks like I might have done somthing wrong probably
barnabasj
barnabasj•3w ago
Are you on the same Ash version that's also used in the tunez repo? Looked at the code, I think it happens because you created your own read action. It seems that the default read action sets up some pagination defaults as well.
if type == :read do
Ash.Resource.Builder.prepend_action(dsl_state, type, type,
primary?: primary?,
transaction?: false,
pagination:
Ash.Resource.Builder.build_pagination(
required?: false,
offset?: true,
keyset?: true,
countable: Ash.DataLayer.data_layer_can?(dsl_state, {:query_aggregate, :count})
)
)
if type == :read do
Ash.Resource.Builder.prepend_action(dsl_state, type, type,
primary?: primary?,
transaction?: false,
pagination:
Ash.Resource.Builder.build_pagination(
required?: false,
offset?: true,
keyset?: true,
countable: Ash.DataLayer.data_layer_can?(dsl_state, {:query_aggregate, :count})
)
)
so what you would need to do to make your version work is set those options in your read action.
read :read do
primary? true

pagination do
required false
offset? true
keyset? true
end
end
read :read do
primary? true

pagination do
required false
offset? true
keyset? true
end
end
EAJ
EAJOP•3w ago
I think you're right! Changing it to the default :read solved the problem. Thanks! 🫶
Rebecca Le
Rebecca Le•2w ago
oooh I didn't know that default read actions did this, good to know

Did you find this page helpful?