Skip to content

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

@petri

Description

@petri

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... ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdata layerPertains to data layers.needs-triagestaleIssue has not had recent activity or appears to be solved. Stale issues will be automatically closed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions