Fix attribute replacement in storage (#1778)

This commit is contained in:
Jonatan Kłosko 2023-03-13 16:27:25 +01:00 committed by GitHub
parent 86ddd68ca0
commit 6e4c81edae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -239,8 +239,11 @@ defmodule Livebook.Storage do
defp delete_keys(table, namespace, entity_id, keys) do
match_head = {{namespace, entity_id}, :"$1", :_, :_}
guards = Enum.map(keys, &{:==, :"$1", &1})
guard =
keys
|> Enum.map(&{:==, :"$1", &1})
|> Enum.reduce(&{:orelse, &1, &2})
:ets.select_delete(table, [{match_head, guards, [true]}])
:ets.select_delete(table, [{match_head, [guard], [true]}])
end
end

View file

@ -33,6 +33,8 @@ defmodule Livebook.StorageTest do
key2: "val2",
key3: "val3"
}} = Storage.fetch(:insert, "replace")
assert {:ok, "updated_val1"} = Storage.fetch_key(:insert, "replace", :key1)
end
end