fix(config): guard against None when meta lacks generated_by key - #2943
Open
devteamaegis wants to merge 3 commits into
Open
fix(config): guard against None when meta lacks generated_by key#2943devteamaegis wants to merge 3 commits into
devteamaegis wants to merge 3 commits into
Conversation
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
devteamaegis
requested review from
asvishnyakov,
hayescode and
sandangel
as code owners
May 31, 2026 18:39
Collaborator
|
@codex review |
dokterbob
requested changes
Jul 29, 2026
dokterbob
left a comment
Collaborator
There was a problem hiding this comment.
Code looks good, thanks! Please fix formatting/linting issues!
dokterbob
enabled auto-merge
July 29, 2026 13:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's broken
In
load_settings(), the conditionmeta.get("generated_by") <= "0.3.0"raisesTypeErrorwhen the[meta]section exists inconfig.tomlbut thegenerated_bykey is absent.meta.get("generated_by")returnsNone, andNone <= stris unsupported in Python 3. The guardnot metaonly short-circuits onNoneor 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 Nonebefore the comparison. The existingif not generated_bybranch handles bothNone(missing key) and empty string, so the behaviour is correct: a config withoutgenerated_byis treated as outdated.Test
Added
TestLoadSettingsMetaGuard.test_meta_section_without_generated_by_raises_value_errorwhich writes a TOML file with[meta]but nogenerated_by, monkeypatchesconfig_file, and assertsValueError(notTypeError) is raised.Fixes #2942
Summary by cubic
Guard against missing
generated_byin[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.