Skip to content

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

Open
devteamaegis wants to merge 3 commits 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 3 commits into
Chainlit:mainfrom
devteamaegis:fix/none-empty-iter-crash

Conversation

@devteamaegis

@devteamaegis devteamaegis commented May 31, 2026

Copy link
Copy Markdown

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

Guard against missing generated_by in [meta] during config loading to prevent a TypeError; such configs are treated as outdated and raise a clear ValueError.

Written for commit f71dae9. 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

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

Copy link
Copy Markdown
Contributor

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

@dokterbob

Copy link
Copy Markdown
Collaborator

@codex review

@dokterbob dokterbob left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thanks!

@dokterbob dokterbob left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code looks good, thanks! Please fix formatting/linting issues!

@devteamaegis

@dokterbob
dokterbob enabled auto-merge July 29, 2026 13:55
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

2 participants