From 4a8e710f8fcaf91cb7882011903637efefa99d72 Mon Sep 17 00:00:00 2001 From: yi111 <153097222+Yi-111-a@users.noreply.github.com> Date: Wed, 21 Oct 2026 18:28:49 +0000 Subject: [PATCH] fix: reject an unrecognized DB_ENGINE instead of using SQLite (#8605) --- mealie/core/settings/db_providers.py | 6 +++++- tests/unit_tests/test_config.py | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mealie/core/settings/db_providers.py b/mealie/core/settings/db_providers.py index 3095c41df..9404b83ea 100644 --- a/mealie/core/settings/db_providers.py +++ b/mealie/core/settings/db_providers.py @@ -81,7 +81,11 @@ class PostgresProvider(AbstractDBProvider, BaseSettings): def db_provider_factory(provider_name: str, data_dir: Path, env_file: Path, env_encoding="utf-8") -> AbstractDBProvider: + # Documented engines are only sqlite and postgres. Anything else used to + # fall through to SQLite, so a typo such as "postgress" started a Postgres + # deployment on a local file and reported success. if provider_name == "postgres": return PostgresProvider(_env_file=env_file, _env_file_encoding=env_encoding) - else: + if provider_name == "sqlite": return SQLiteProvider(data_dir=data_dir) + raise ValueError(f"DB_ENGINE must be 'sqlite' or 'postgres', got {provider_name!r}") diff --git a/tests/unit_tests/test_config.py b/tests/unit_tests/test_config.py index f5835b25e..24855b38b 100644 --- a/tests/unit_tests/test_config.py +++ b/tests/unit_tests/test_config.py @@ -69,6 +69,13 @@ def test_pg_connection_args(monkeypatch): assert app_settings.DB_URL == "postgresql+psycopg2://mealie:mealie@postgres:5432/mealie" +def test_unknown_db_engine_is_rejected(monkeypatch): + monkeypatch.setenv("DB_ENGINE", "postgress") + get_app_settings.cache_clear() + with pytest.raises(ValueError, match="DB_ENGINE"): + get_app_settings() + + psql_validation_cases = [ ( "unencoded_to_encoded_password",