Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/chainlit/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __post_init__(self) -> None:
self.id = str(uuid.uuid4())

@classmethod
def from_dict(self, _dict: StepDict):
def from_dict(cls, _dict: StepDict):
type = _dict.get("type", "assistant_message")
return Message(
id=_dict["id"],
Expand Down
4 changes: 2 additions & 2 deletions backend/chainlit/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def async_wrapper(*args, **kwargs):
logger.exception(e)
result = await func(*args, **kwargs)
try:
if result and not step.output:
if result is not None and not step.output:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice fix. I think it would be worth adding a small regression test for the exact falsy return case this changes.

The existing step decorator tests cover normal truthy returns, but this PR changes both the async and sync wrappers to preserve falsy non-None values. A test with @step functions returning something like 0 or False would lock in the difference between “no return value” and “a real falsy return value”.

It'd be good to add some coverage for both async and sync decorated functions, and assert that the updated step output captures those values.

step.output = result
except Exception as e:
step.is_error = True
Expand Down Expand Up @@ -154,7 +154,7 @@ def sync_wrapper(*args, **kwargs):
logger.exception(e)
result = func(*args, **kwargs)
try:
if result and not step.output:
if result is not None and not step.output:
step.output = result
except Exception as e:
step.is_error = True
Expand Down