Do not crash on invalid atom in configDB

This commit is contained in:
FloatingGhost 2022-12-21 00:16:39 +00:00
parent 4a78c431cf
commit af7c3fab98
4 changed files with 15 additions and 1 deletions

View file

@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- /api/v1/accounts/lookup will now respect restrict\_unauthenticated
- Unknown atoms in the config DB will no longer crash akkoma on boot
### Upgrade notes
- Ensure `config :tesla, :adapter` is either unset, or set to `{Tesla.Adapter.Finch, name: MyFinch}` in your .exs config

View file

@ -42,6 +42,7 @@ defmodule Pleroma.Config.TransferTask do
# We need to restart applications for loaded settings take effect
{logger, other} =
(Repo.all(ConfigDB) ++ deleted_settings)
|> Enum.reject(&invalid_key_or_group/1)
|> Enum.map(&merge_with_default/1)
|> Enum.split_with(fn {group, _, _, _} -> group == :logger end)
@ -85,6 +86,10 @@ defmodule Pleroma.Config.TransferTask do
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
default =
if group == :pleroma do

View file

@ -342,7 +342,11 @@ defmodule Pleroma.ConfigDB do
def string_to_elixir_types(value) do
if module_name?(value) do
try do
String.to_existing_atom("Elixir." <> value)
rescue
ArgumentError -> :invalid_atom
end
else
value
end

View file

@ -227,6 +227,10 @@ defmodule Pleroma.ConfigDBTest do
assert ConfigDB.to_elixir_types("Pleroma.Bookmark") == Pleroma.Bookmark
end
test "removed module" do
assert ConfigDB.to_elixir_types("Pleroma.Nowhere") == :invalid_atom
end
test "pleroma string" do
assert ConfigDB.to_elixir_types("Pleroma") == "Pleroma"
end