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: Include element props in SQLAlchemyDataLayer query for elements #1949

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

ckrapu-nv
Copy link
Contributor

Description

Fixes an issue arising with SQLAlchemyDataLayer in which a custom element's state would not be properly reloaded after resuming a chat thread due to a null value for the element's props. #1799 documents the issue in more detail, including a fix.

Problem

In sql_alchemy.py, the SQL query contained in elements_query is missing the props. Since this is missing, any reloaded custom element will have an empty value for props thereby ignoring its latest state.

Also, there was an error on insertion of new elements into the database in an identical fashion to #1794 which fixes the same error in the default Postgres data layer. This PR includes the same fix for the SQLAlchemyDataLayer which also blocked a successful element refresh workflow.

Steps to Reproduce

  • Create an application with a custom Element
  • Use the SQLAlchemyDataLayer for persistence
  • Create a Chainlit app instantiating the custom Element
  • Update the state of the element
  • Refresh the page or create a new conversation, then switch back to the original one

Solution and Changes

Add the props field to the query and use props=element.get("props", "{}") instead of props=json.loads(element.get("props", "{}"))

Testing

  • Ran pytest from backend/ with no failures or errors and all tests finishing.
  • Successfully tested with my application which uses the S3 storage client and SQLAlchemyDataLayer with Azure PostgreSQL (flexible server). I created two new chat threads, triggered the custom element creation, and created a third chat. I then switched back to the two earlier chat threads and verified that the elements' props were loaded and the element state was properly set.

Copy link
Collaborator

@willydouhard willydouhard left a comment

Choose a reason for hiding this comment

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

lgtm

@willydouhard willydouhard added this pull request to the merge queue Mar 3, 2025
Merged via the queue into Chainlit:main with commit 072655d Mar 3, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data layer Pertains to data layers. size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants