Skip to content

fix(config): guard against None when meta lacks generated_by key#2943

Open
devteamaegis wants to merge 1 commit into
Chainlit:mainfrom
devteamaegis:fix/none-empty-iter-crash
Open

fix(config): guard against None when meta lacks generated_by key#2943
devteamaegis wants to merge 1 commit into
Chainlit:mainfrom
devteamaegis:fix/none-empty-iter-crash

Conversation

@devteamaegis
Copy link
Copy Markdown

@devteamaegis devteamaegis commented May 31, 2026

What's broken

In load_settings(), the condition meta.get("generated_by") <= "0.3.0" raises TypeError when the [meta] section exists in config.toml but the generated_by key is absent. meta.get("generated_by") returns None, and None <= str is unsupported in Python 3. The guard not meta only short-circuits on None or empty dict, not on a non-empty dict with a missing key.

Why it happens

The version comparison was written assuming meta.get("generated_by") always returns a string, but the key can be missing even when [meta] is present.

Fix

Extract generated_by = meta.get("generated_by") if meta else None before the comparison. The existing if not generated_by branch handles both None (missing key) and empty string, so the behaviour is correct: a config without generated_by is treated as outdated.

Test

Added TestLoadSettingsMetaGuard.test_meta_section_without_generated_by_raises_value_error which writes a TOML file with [meta] but no generated_by, monkeypatches config_file, and asserts ValueError (not TypeError) is raised.

Fixes #2942


Summary by cubic

Prevented a TypeError in config loading when a [meta] section exists without generated_by by guarding the value before version comparison. Such configs are now treated as outdated and raise a clear ValueError instead of crashing.

Written for commit a083888. Summary will update on new commits.

Review in cubic

When a config.toml [meta] section exists but omits the generated_by key,
meta.get("generated_by") returns None, causing a TypeError on the
None <= str comparison. Extract generated_by before the check so a
missing key is treated as outdated rather than crashing.

Fixes Chainlit#2942
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. backend Pertains to the Python backend. bug Something isn't working unit-tests Has unit tests. labels May 31, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Pertains to the Python backend. bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files. unit-tests Has unit tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: TypeError when [meta] section exists but lacks 'generated_by' key in config.toml

1 participant