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: Add Cascade Delete Function for Transactions and Builds Associated with Flows #3848

Merged
merged 7 commits into from
Sep 18, 2024

Conversation

Cristhianzl
Copy link
Collaborator

This pull request introduces a cascade delete function to address an issue where deleting a flow would sometimes fail due to related transactions and builds not being properly removed. The new function ensures that all associated transactions and builds of a flow are deleted before the flow itself is removed. This resolves errors that occurred when attempting to delete folders containing flows.

This commit adds a new function `cascade_delete_flow` to the `utils.py` file in the `langflow.api` module. This function is responsible for deleting related records when a flow is deleted. It uses the `delete` method from SQLAlchemy to delete records from the `TransactionTable` and `VertexBuildTable` tables based on the flow ID. Finally, it deletes the flow record itself from the `Flow` table.

The function is wrapped in a try-except block to handle any exceptions that may occur during the deletion process. If an exception is raised, a `RuntimeError` is raised with an appropriate error message.

This refactor improves the code by encapsulating the cascade delete logic in a separate function, making it more modular and easier to maintain.
@Cristhianzl Cristhianzl self-assigned this Sep 18, 2024
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Sep 18, 2024
@github-actions github-actions bot added bug Something isn't working and removed enhancement New feature or request labels Sep 18, 2024
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-3848.dmtpw4p5recq1.amplifyapp.com

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 18, 2024
@Cristhianzl Cristhianzl enabled auto-merge (squash) September 18, 2024 17:48
@Cristhianzl Cristhianzl merged commit 323d514 into main Sep 18, 2024
30 checks passed
@Cristhianzl Cristhianzl deleted the cz/fixFoldersDelete branch September 18, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants