Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SQLAlchemyDataLayer): Fix sqlite json columns #1817

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 10 additions & 6 deletions backend/chainlit/data/sql_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,14 +637,18 @@ async def get_all_user_threads(
for thread in user_threads:
thread_id = thread["thread_id"]
if thread_id is not None:
# SQLite returns JSON as string, we most convert it.
thread_metadata = thread.get("thread_metadata", {})
if isinstance(thread_metadata, str):
thread_metadata = json.loads(thread_metadata)
thread_dicts[thread_id] = ThreadDict(
id=thread_id,
createdAt=thread["thread_createdat"],
name=thread["thread_name"],
userId=thread["user_id"],
userIdentifier=thread["user_identifier"],
tags=thread["thread_tags"],
metadata=thread["thread_metadata"],
metadata=thread_metadata,
steps=[],
elements=[],
)
Expand All @@ -661,6 +665,10 @@ async def get_all_user_threads(
value=step_feedback["feedback_value"],
comment=step_feedback.get("feedback_comment"),
)
# SQLite returns JSON as string, we most convert it.
step_metadata = step_feedback.get("step_metadata", {})
if isinstance(step_metadata, str):
step_metadata = json.loads(step_metadata)
step_dict = StepDict(
id=step_feedback["step_id"],
name=step_feedback["step_name"],
Expand All @@ -670,11 +678,7 @@ async def get_all_user_threads(
streaming=step_feedback.get("step_streaming", False),
waitForAnswer=step_feedback.get("step_waitforanswer"),
isError=step_feedback.get("step_iserror"),
metadata=(
step_feedback["step_metadata"]
if step_feedback.get("step_metadata") is not None
else {}
),
metadata=step_metadata,
tags=step_feedback.get("step_tags"),
input=(
step_feedback.get("step_input", "")
Expand Down
Loading