diff --git a/backend/chainlit/config.py b/backend/chainlit/config.py index a540752b33..3e7931590e 100644 --- a/backend/chainlit/config.py +++ b/backend/chainlit/config.py @@ -633,7 +633,8 @@ def load_settings(): ui_settings = toml_dict.get("UI", {}) meta = toml_dict.get("meta") - if not meta or meta.get("generated_by") <= "0.3.0": + generated_by = meta.get("generated_by") if meta else None + if not generated_by or generated_by <= "0.3.0": raise ValueError( f"Your config file '{config_file}' is outdated. Please delete it and restart the app to regenerate it." ) diff --git a/backend/tests/test_config.py b/backend/tests/test_config.py index a1f9dff15f..324b77fe4a 100644 --- a/backend/tests/test_config.py +++ b/backend/tests/test_config.py @@ -7,6 +7,21 @@ from chainlit.config import ChainlitConfig +class TestLoadSettingsMetaGuard: + """Regression test: meta section with missing generated_by must not raise TypeError.""" + + def test_meta_section_without_generated_by_raises_value_error( + self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch + ): + """[meta] present but lacking 'generated_by' should raise ValueError, not TypeError.""" + toml_content = "[meta]\nsome_other_key = \"value\"\n" + cfg_file = tmp_path / "config.toml" + cfg_file.write_text(toml_content, encoding="utf-8") + monkeypatch.setattr(chainlit_config, "config_file", str(cfg_file)) + with pytest.raises(ValueError, match="outdated"): + chainlit_config.load_settings() + + @pytest.fixture def translation_dir(tmp_path: Path) -> Path: """Minimal translation directory with a controlled set of locale files."""