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: threadId assignment to first user message #1960

Merged
merged 2 commits into from
Mar 7, 2025

Conversation

Dan-data-tech
Copy link
Contributor

Describe the bug
In SQLAlchemy data layer, create_step is executed before update_thread which prevents first user message from being saved in the database with a threadId assigned resulting in cutting it out when on_chat_resume is triggered.

Here's what happened when I send the first message to the UI:

An error occurred: (sqlalchemy.dialects.postgresql.asyncpg.IntegrityError) <class 'asyncpg.exceptions.ForeignKeyViolationError'>: insert or update on table "steps" violates foreign key constraint "steps_threadId_fkey"
DETAIL: Key (threadId)=(7bfc3437-cf41-417f-8fbb-642fa25b420d) is not present in table "threads".

How I fixed it
I added this line of code at the beginning of 'create_step' function:

await self.update_thread(step_dict["threadId"])

forcing update_thread to be executed first.

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working data layer Pertains to data layers. labels Mar 6, 2025
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
Copy link
Collaborator

Please run ruff check --fix and ruff format in the backend dir. CI is red.

@willydouhard willydouhard added this pull request to the merge queue Mar 7, 2025
Merged via the queue into Chainlit:main with commit cbdaafb Mar 7, 2025
9 checks passed
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. size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants