AE
Ash Elixir•2y ago
Francis

AshCsv - duplication on `upsert?: true`

I might be doing something wrong but when using AshCsv with upsert?: true on a create action, I get duplicates in the CSV file. For context, here's the ressource
elixir

defmodule WorkoutManager.Exercises.Equipment do
@moduledoc false

alias WorkoutManager.Exercises

use Ash.Resource,
data_layer: AshCsv.DataLayer

csv do
file "priv/exercises/equipment.csv"
create? true
header? true
columns [:name]
end

attributes do
attribute :name, :ci_string do
allow_nil? false
primary_key? true
constraints casing: :lower
end
end

actions do
defaults [:read, :destroy]

create :upsert do
accept [:name]
upsert? true
end
end

code_interface do
define_for Exercises

define :read_all, action: :read
define :upsert, args: [:name]
define :destroy
end
end
elixir

defmodule WorkoutManager.Exercises.Equipment do
@moduledoc false

alias WorkoutManager.Exercises

use Ash.Resource,
data_layer: AshCsv.DataLayer

csv do
file "priv/exercises/equipment.csv"
create? true
header? true
columns [:name]
end

attributes do
attribute :name, :ci_string do
allow_nil? false
primary_key? true
constraints casing: :lower
end
end

actions do
defaults [:read, :destroy]

create :upsert do
accept [:name]
upsert? true
end
end

code_interface do
define_for Exercises

define :read_all, action: :read
define :upsert, args: [:name]
define :destroy
end
end
This happens when I call WorkoutManager.Exercises.Equipment.upsert!("rings") multiple times. The behaviour I was expecting was that if rings was already in the file, it wouldn't duplicate it but it inserts a duplicate.
3 Replies
ZachDaniel
ZachDaniel•2y ago
🤔 it should looking into it okay, just released a fix
Francis
FrancisOP•2y ago
Awesome! Thanks for looking into it so quickly! Tried to upgrade to 0.9.3 but it seems like ash_csv isn't compatible with newer versions of ash? 🤔 Got the following error when running mix deps.update ash_csv:
Resolving Hex dependencies...
Resolution completed in 0.052s
Because ash_csv >= 0.9.3 depends on ash ~> 2.6.11 and your app depends on ash ~> 2.9, ash_csv >= 0.9.3 is forbidden.
So, because your app depends on ash_csv ~> 0.9.3, version solving failed.
** (Mix) Hex dependency resolution failed
Resolving Hex dependencies...
Resolution completed in 0.052s
Because ash_csv >= 0.9.3 depends on ash ~> 2.6.11 and your app depends on ash ~> 2.9, ash_csv >= 0.9.3 is forbidden.
So, because your app depends on ash_csv ~> 0.9.3, version solving failed.
** (Mix) Hex dependency resolution failed
ZachDaniel
ZachDaniel•2y ago
one sec, lemme check just reelased 0.9.4

Did you find this page helpful?