Do not crash on invalid atom in configDB
This commit is contained in:
parent
4a78c431cf
commit
af7c3fab98
4 changed files with 15 additions and 1 deletions
|
@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- /api/v1/accounts/lookup will now respect restrict\_unauthenticated
|
- /api/v1/accounts/lookup will now respect restrict\_unauthenticated
|
||||||
|
- Unknown atoms in the config DB will no longer crash akkoma on boot
|
||||||
|
|
||||||
### Upgrade notes
|
### Upgrade notes
|
||||||
- Ensure `config :tesla, :adapter` is either unset, or set to `{Tesla.Adapter.Finch, name: MyFinch}` in your .exs config
|
- Ensure `config :tesla, :adapter` is either unset, or set to `{Tesla.Adapter.Finch, name: MyFinch}` in your .exs config
|
||||||
|
|
|
@ -42,6 +42,7 @@ defmodule Pleroma.Config.TransferTask do
|
||||||
# We need to restart applications for loaded settings take effect
|
# We need to restart applications for loaded settings take effect
|
||||||
{logger, other} =
|
{logger, other} =
|
||||||
(Repo.all(ConfigDB) ++ deleted_settings)
|
(Repo.all(ConfigDB) ++ deleted_settings)
|
||||||
|
|> Enum.reject(&invalid_key_or_group/1)
|
||||||
|> Enum.map(&merge_with_default/1)
|
|> Enum.map(&merge_with_default/1)
|
||||||
|> Enum.split_with(fn {group, _, _, _} -> group == :logger end)
|
|> Enum.split_with(fn {group, _, _, _} -> group == :logger end)
|
||||||
|
|
||||||
|
@ -85,6 +86,10 @@ defmodule Pleroma.Config.TransferTask do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp invalid_key_or_group(%ConfigDB{key: :invalid_atom}), do: true
|
||||||
|
defp invalid_key_or_group(%ConfigDB{group: :invalid_atom}), do: true
|
||||||
|
defp invalid_key_or_group(_), do: false
|
||||||
|
|
||||||
defp merge_with_default(%{group: group, key: key, value: value} = setting) do
|
defp merge_with_default(%{group: group, key: key, value: value} = setting) do
|
||||||
default =
|
default =
|
||||||
if group == :pleroma do
|
if group == :pleroma do
|
||||||
|
|
|
@ -342,7 +342,11 @@ defmodule Pleroma.ConfigDB do
|
||||||
|
|
||||||
def string_to_elixir_types(value) do
|
def string_to_elixir_types(value) do
|
||||||
if module_name?(value) do
|
if module_name?(value) do
|
||||||
|
try do
|
||||||
String.to_existing_atom("Elixir." <> value)
|
String.to_existing_atom("Elixir." <> value)
|
||||||
|
rescue
|
||||||
|
ArgumentError -> :invalid_atom
|
||||||
|
end
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
|
@ -227,6 +227,10 @@ defmodule Pleroma.ConfigDBTest do
|
||||||
assert ConfigDB.to_elixir_types("Pleroma.Bookmark") == Pleroma.Bookmark
|
assert ConfigDB.to_elixir_types("Pleroma.Bookmark") == Pleroma.Bookmark
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "removed module" do
|
||||||
|
assert ConfigDB.to_elixir_types("Pleroma.Nowhere") == :invalid_atom
|
||||||
|
end
|
||||||
|
|
||||||
test "pleroma string" do
|
test "pleroma string" do
|
||||||
assert ConfigDB.to_elixir_types("Pleroma") == "Pleroma"
|
assert ConfigDB.to_elixir_types("Pleroma") == "Pleroma"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue