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

Missing JSON deserialization in SQLAlchemy data layer when using SQLite #1545

Open
petri opened this issue Nov 27, 2024 · 1 comment
Open
Labels
bug Something isn't working data layer Pertains to data layers. needs-triage

Comments

@petri
Copy link

petri commented Nov 27, 2024

Describe the bug

When using the SQLAlchemy data layer with SQLite, in get_all_user_threads(), the returned metadata seems to be a JSON string but it is not ever deserialized.

metadata=thread["thread_metadata"],

For me, backend/chainlit/socket.py, line 53 in resume_thread() subsequently fails attempting metadata.copy() triggered by having an implementation of @on_chat_resume.

Interestingly, similar case seems to be correctly handled elsewhere in the same module:

# SQLite returns JSON as string, we most convert it. (#1137)
metadata = user_data.get("metadata", {})
if isinstance(metadata, str):
metadata = json.loads(metadata)

Given that, I'd go as far as to suggest the whole module should be reviewed; there might be other places where deserialization is missing.

To Reproduce

Try out anything that uses the metadata using SQLAlchemy + SQLite. I tried on_chat_resume which appears to trigger the problematic code.

For what it's worth, I thought SQLAlchemy handled this kind of differences transparently, unless it is being used in a low-level way... ?

@petri petri changed the title Missing JSON deserialization in SQLAlchemy data layer when using SQLite (at least) Missing JSON deserialization in SQLAlchemy data layer when using SQLite Nov 27, 2024
@dosubot dosubot bot added bug Something isn't working data layer Pertains to data layers. labels Nov 27, 2024
@petri
Copy link
Author

petri commented Nov 27, 2024

Re other places possibly needing a fix, line 652 has this ... no idea if it needs fixing or not.

metadata=(
    step_feedback["step_metadata"]
    if step_feedback.get("step_metadata") is not None
    else {}
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working data layer Pertains to data layers. needs-triage
Projects
None yet
Development

No branches or pull requests

1 participant