Skip to content
New issue

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

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

Already on GitHub? # to your account

Bug: removing projects with associated messages fails with an IntegrityError #5925

Open
Naroh091 opened this issue Jan 24, 2025 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Naroh091
Copy link

Bug Description

Hi! First of all, thanks for the amazing work developing Langflow - It's an amazing product.

I just noticed that removing projects with playground messages fails with this toast:

Image

This is because the project has associated relations that are not removed at the time of the request.

{
    "detail": "('Unable to cascade delete flow: $563be498-2655-4011-bcb9-766cbbf0eb7f', IntegrityError('(psycopg.errors.ForeignKeyViolation) update or delete on table \"flow\" violates foreign key constraint \"message_flow_id_fkey\" on table \"message\"\\nDETAIL:  Key (id)=(563be498-2655-4011-bcb9-766cbbf0eb7f) is still referenced from table \"message\".'))"
}

I'd be happy to send the fix, but first I'd like if the preferred solution is to request a confirmation when the project to remove has associated messages or if we should delete it transparently.

Thanks!

Reproduction

Steps to reproduce:

  1. Create a project
  2. Use the playground to start a conversation
  3. Try to remove the project
  4. It fails

Expected behavior

Shouldn't fail, either asking the user for confirmation when messages exist or removing them without confirmation.

Who can help?

No response

Operating System

Ubuntu Server 24.04

Langflow Version

1.1.2

Python Version

3.12

Screenshot

No response

Flow File

No response

@Naroh091 Naroh091 added the bug Something isn't working label Jan 24, 2025
@Naroh091 Naroh091 changed the title Bug: removing projects with associated messages fail with an IntegrityError Bug: removing projects with associated messages fails with an IntegrityError Jan 24, 2025
Copy link

dosubot bot commented Jan 24, 2025

Hey @Naroh091! 👋 I'm here to help you with bugs, questions, and even becoming a contributor. Let's squash those bugs together!

The issue you're encountering is due to a foreign key constraint violation when attempting to delete a project with associated messages. The cascade_delete_flow function currently does not handle the deletion of messages associated with a flow, which leads to the IntegrityError you are seeing [1].

To address this, you have two potential solutions:

  1. Request Confirmation: Before deleting a project, check if there are associated messages. If there are, prompt the user for confirmation to delete both the project and its messages. This approach aligns with the existing confirmation mechanism in the Langflow UI for deleting components [2].

  2. Transparent Deletion: Modify the cascade_delete_flow function to include the deletion of messages associated with the project. This would involve uncommenting and ensuring the safety of the message deletion line in the function:

    await session.exec(delete(MessageTable).where(MessageTable.flow_id == flow_id))

    This approach would automatically remove all related messages when a project is deleted, without requiring user confirmation.

Both approaches have their merits. Requesting confirmation provides users with control over data deletion, while transparent deletion simplifies the process by automatically cleaning up related data. Choose the approach that best fits the user experience you want to provide in Langflow.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@Cristhianzl
Copy link
Member

Cristhianzl commented Jan 27, 2025

Hi @Naroh091,

I couldn’t reproduce this error locally. I tested it using the latest version of LangFlow (1.1.2) available on main, running both via make and with the command:

uv run langflow run

Could you please provide more context on how you’re running LangFlow? Additionally, please ensure you’re using our latest version. You can find instructions on managing LangFlow versions here: [LangFlow Update Guide].

Thanks for your feedback.

@Naroh091
Copy link
Author

@Cristhianzl I'm running the Docker image connected to the Postgresql container under Ubuntu Server 24.04. It's not a fresh install but an update from 1.1.1 - maybe some migration was missing? I'll try to locally reproduce the issue this week.

@Cristhianzl
Copy link
Member

Hi @Naroh091,

The issue seems to be related to the "messages" table, which is used to store message history for flows with memory functionality. You can safely delete the records in this table to resolve the immediate problem.

The error you're encountering is likely related to a migration issue during the version upgrade. To better diagnose the root cause, I would need to see more detailed logs from your environment.

For local development, we provide utility commands to handle database migrations:

make alembic-upgrade    # Apply pending migrations
make alembic-check     # Check migration status

Please try these commands and let me know if you need any further assistance or if the issue persists.

@italojohnny
Copy link
Member

Hello, @Naroh091

I don't think this is a migration issue.

I tried to reproduce the problem in my environment using Docker containers for Langflow and Postgres. I deleted the flow through the frontend UI, and everything worked fine. Then, I created a flow on branch v1.1.1, updated to branch v1.1.2, and deleted it again through the UI. Everything worked perfectly once more.

Additionally, I tried deleting the flow directly from the database using:

DELETE FROM flow WHERE name = 'my_project';

However, the database returned a constraint error that prevented the operation, as expected.

Image

In summary, I couldn't reproduce your issue, even when deliberately trying to break things.
We need more details to reproduce the problem on our side.

@Cristhianzl
Copy link
Member

hi @Naroh091 @italojohnny

Please follow up this PR with the fix: #6667

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants