diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b99a0e3c..d556b39c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index 4fcaab4a5..52f6346a5 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -42,6 +42,7 @@ def load_and_update_env(deleted_settings \\ [], restart_pleroma? \\ true) 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 @@ defp maybe_set_pleroma_last(apps) 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 diff --git a/lib/pleroma/config_db.ex b/lib/pleroma/config_db.ex index 77f2c4e2d..9e4e6f3ea 100644 --- a/lib/pleroma/config_db.ex +++ b/lib/pleroma/config_db.ex @@ -342,7 +342,11 @@ def string_to_elixir_types(":" <> atom), do: String.to_atom(atom) def string_to_elixir_types(value) do if module_name?(value) do - String.to_existing_atom("Elixir." <> value) + try do + String.to_existing_atom("Elixir." <> value) + rescue + ArgumentError -> :invalid_atom + end else value end diff --git a/test/pleroma/config_db_test.exs b/test/pleroma/config_db_test.exs index e68346ce4..3f1a5519b 100644 --- a/test/pleroma/config_db_test.exs +++ b/test/pleroma/config_db_test.exs @@ -227,6 +227,10 @@ test "pleroma module" 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