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: Improve data consistency in update_flow function #5516

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

Cristhianzl
Copy link
Member

This pull request includes several changes to the update_flow function and a utility function in the backend of the Langflow API. The modifications aim to improve error handling, ensure data integrity, and enhance functionality.

Improvements to update_flow function:

  • Added a check to set flow.data to db_flow.data if it is None to ensure data consistency.
  • Added a return statement to return db_flow after committing the session, ensuring the updated flow is returned.
  • Moved the session rollback inside the except block to handle errors more gracefully and ensure the database state is not corrupted.

Enhancements to utility function:

  • Added a check for the presence of "nodes" in flow_data to prevent potential attribute errors in the get_webhook_component_in_flow function.

…d in the database during flow update

📝 (flows.py): Improve error handling and rollback database session in case of exceptions during flow update
📝 (flows.py): Refactor code to handle unique constraint errors and provide more informative error messages
📝 (utils.py): Refactor get_webhook_component_in_flow function to handle cases where flow_data may not have 'nodes' attribute
@Cristhianzl Cristhianzl self-assigned this Jan 2, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jan 2, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 2, 2025
@Cristhianzl Cristhianzl marked this pull request as draft January 2, 2025 16:26
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 2, 2025
Copy link

codspeed-hq bot commented Jan 2, 2025

CodSpeed Performance Report

Merging #5516 will improve performances by 26.12%

Comparing cz/fix-move-flow-folder (57d562b) with main (70eaacf)

Summary

⚡ 2 improvements
✅ 13 untouched benchmarks

Benchmarks breakdown

Benchmark main cz/fix-move-flow-folder Change
test_get_and_cache_all_types_dict 1.3 ms 1 ms +26.12%
test_successful_run_with_output_type_debug 352.5 ms 299.7 ms +17.63%

…r folder buttons for improved accessibility and testing

✨ (general-bugs-move-flow-from-folder.spec.ts): add test to ensure user can move flow from one folder to another in the frontend application
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 2, 2025
@Cristhianzl Cristhianzl marked this pull request as ready for review January 2, 2025 18:16
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 2, 2025
…l data inconsistency

♻️ (service.py): refactor with_session method to handle session commit and rollback more effectively
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 3, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 6, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 8, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jan 8, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 8, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 8, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 8, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 8, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 8, 2025
@Cristhianzl Cristhianzl enabled auto-merge January 8, 2025 15:00
src/backend/base/langflow/services/database/service.py Outdated Show resolved Hide resolved
Comment on lines +278 to +279
if flow.data is None:
flow.data = db_flow.data
Copy link
Contributor

Choose a reason for hiding this comment

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

if we are saving db_flow, why are we setting this here?

Can't we just do something like `flow.model_dump(exclude_unset=True, exclude_none=True?)

Copy link
Member Author

Choose a reason for hiding this comment

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

this is because in some cases, the frontend needs to update parts of the flow (such as the description or name) without sending all the data to the backend. In these situations, we must retrieve the data from the database to save the changes..

Copy link
Contributor

Choose a reason for hiding this comment

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

But the db_flow is the one being added to the database already.

Copy link
Contributor

Choose a reason for hiding this comment

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

We are putting db_flow data into flow then saving db_flow. We don't need to do that.

Again: can't we just do something like flow.model_dump(exclude_unset=True, exclude_none=True)?

@dosubot dosubot bot removed the lgtm This PR has been approved by a maintainer label Jan 9, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 10, 2025
@github-actions github-actions bot added bug Something isn't working and removed bug Something isn't working labels Jan 10, 2025
Comment on lines +278 to +279
if flow.data is None:
flow.data = db_flow.data
Copy link
Contributor

Choose a reason for hiding this comment

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

But the db_flow is the one being added to the database already.

Comment on lines +278 to +279
if flow.data is None:
flow.data = db_flow.data
Copy link
Contributor

Choose a reason for hiding this comment

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

We are putting db_flow data into flow then saving db_flow. We don't need to do that.

Again: can't we just do something like flow.model_dump(exclude_unset=True, exclude_none=True)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants