fix(step): use 'is not None' guard to preserve falsy return values in @step decorator#2940
Open
devteamaegis wants to merge 2 commits into
Open
fix(step): use 'is not None' guard to preserve falsy return values in @step decorator#2940devteamaegis wants to merge 2 commits into
devteamaegis wants to merge 2 commits into
Conversation
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.
Summary
Two fixes in the messaging layer:
1.
step.py— falsy-output silently dropped (primary bug)The
@stepdecorator records the decorated function's return value via:A plain truthiness guard (
if result) silently drops any falsy-but-meaningful return value:0,False,"",[],{}, etc.Example:
The
0return is falsy, sostep.outputis never set. The step appears to have no output in the UI, and the value is not persisted.Fix: Use
result is not None— only skip recording when the function explicitly returns nothing.This applies to both the
async_wrapperandsync_wrapperpaths.2.
message.py—@classmethodnames first parameterselfMessageBase.from_dictis decorated with@classmethodbut its first parameter is namedselfinstead of the conventionalcls. While Python itself doesn't care about the parameter name, type-checkers (mypy, pyright) and linters flag this as an error, and it misleads readers into thinkingselfis an instance.Renamed to
clsfollowing PEP 8 / Python convention.Summary by cubic
Fixes the
@stepdecorator to keep falsy but valid return values (e.g., 0, False, "", [], {}). Ensures step outputs are saved and shown; also aligns a classmethod signature with conventions to satisfy linters.backend/chainlit/step.py: useresult is not Nonein both async and sync wrappers so falsy outputs are recorded.backend/chainlit/message.py: renameselftoclsinfrom_dictto follow classmethod convention and pass type-checkers.Written for commit 98d81cb. Summary will update on new commits.