Skip to content

fix: add ondelete flag to fk in flow version table#12059

Merged
jordanrfrazier merged 12 commits into
mainfrom
on-delete-flow-version
Mar 6, 2026
Merged

fix: add ondelete flag to fk in flow version table#12059
jordanrfrazier merged 12 commits into
mainfrom
on-delete-flow-version

Conversation

@jordanrfrazier
Copy link
Copy Markdown
Collaborator

@jordanrfrazier jordanrfrazier commented Mar 5, 2026

Fixes model / database mismatch. Add ondelete flag to fk in flow version table

Summary by CodeRabbit

  • Chores
    • Database schema migration to support flow versions that can exist independently of user assignments.
    • Enhanced cascade delete relationships to ensure proper data cleanup and consistency when related records are removed from the system.

@github-actions github-actions Bot added the bug Something isn't working label Mar 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 23%
23.24% (8235/35429) 16.02% (4458/27826) 15.91% (1185/7445)

Unit Test Results

Tests Skipped Failures Errors Time
2631 0 💤 0 ❌ 0 🔥 43.301s ⏱️

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 5, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 60f3c614-cd78-49f8-92aa-87bb0508991b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Changes modify database schema to make user_id optional in FlowVersion by allowing NULL values, update the Pydantic read schema accordingly, and refactor TraceBase.flow_id to use explicit SQLModel sa_column configuration with cascade delete behavior instead of the foreign_key argument.

Changes

Cohort / File(s) Summary
FlowVersion Schema Updates
src/backend/base/langflow/alembic/versions/7d327cfafab6_add_flow_history_table.py, src/backend/base/langflow/services/database/models/flow_version/model.py
Made user_id column nullable in flow_version table and updated FlowVersion ORM model with UUID | None type, foreign key SET NULL behavior, and FlowVersionRead schema to match.
Traces Foreign Key Refactor
src/backend/base/langflow/services/database/models/traces/model.py
Refactored TraceBase.flow_id field to use explicit SQLModel sa_column with ForeignKey constraint and ondelete="CASCADE" configuration, replacing the previous foreign_key argument style.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 3 warnings)

Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR modifies critical database schema and models (flow_version migration, FlowVersion model, TraceBase model) but includes no new test files to verify the changes. Add test files to verify migration correctness, model foreign key behavior, nullable fields, and data integrity when deleting related records.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Quality And Coverage ⚠️ Warning Test suite lacks critical tests for SET NULL behavior on user deletion and user_id nullability in flow_version and traces models. Add tests validating SET NULL behavior on user deletion, flow_version with user_id=None, model constraint validation, and traces flow_id CASCADE configuration.
Test File Naming And Structure ⚠️ Warning PR modifies database models and migration file but includes no test files to verify schema changes. Add test files for migration execution and model behavior changes, including tests for nullable user_id and cascade delete scenarios.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding an ondelete flag to the foreign key constraint in the flow_version table, which is the primary fix addressed in this PR.
Excessive Mock Usage Warning ✅ Passed The PR includes two test files with appropriate mock usage: integration tests use real objects while unit tests properly mock external dependencies.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch on-delete-flow-version

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 5, 2026

Migration Validation Passed

All migrations follow the Expand-Contract pattern correctly.

@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Mar 5, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.59%. Comparing base (d43bf3f) to head (432bfc2).
⚠️ Report is 2 commits behind head on main.

❌ Your project status has failed because the head coverage (42.83%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #12059      +/-   ##
==========================================
+ Coverage   37.58%   37.59%   +0.01%     
==========================================
  Files        1623     1623              
  Lines       79603    79604       +1     
  Branches    11971    11971              
==========================================
+ Hits        29917    29928      +11     
+ Misses      48027    48017      -10     
  Partials     1659     1659              
Flag Coverage Δ
backend 57.08% <100.00%> (+0.04%) ⬆️
frontend 20.82% <ø> (ø)
lfx 42.83% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...low/services/database/models/flow_version/model.py 100.00% <100.00%> (ø)
.../langflow/services/database/models/traces/model.py 90.13% <100.00%> (+0.06%) ⬆️

... and 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jordanrfrazier jordanrfrazier enabled auto-merge March 5, 2026 15:17
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 5, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/backend/base/langflow/alembic/versions/7d327cfafab6_add_flow_history_table.py (1)

23-45: ⚠️ Potential issue | 🟠 Major

Do not rely on mutating an existing revision to fix upgraded environments.

Changing nullable behavior inside revision 7d327cfafab6 only affects DBs that have not applied this revision yet. Already-migrated environments will not re-run it, so the mismatch can persist. Add a new forward migration that alters flow_version.user_id nullability/FK explicitly.

Suggested follow-up migration (new revision)
+"""make flow_version.user_id nullable and enforce SET NULL FK"""
+
+from alembic import op
+import sqlalchemy as sa
+
+revision = "NEW_REVISION_ID"
+down_revision = "7d327cfafab6"
+branch_labels = None
+depends_on = None
+
+def upgrade() -> None:
+    with op.batch_alter_table("flow_version") as batch_op:
+        batch_op.alter_column("user_id", existing_type=sa.Uuid(), nullable=True)
+        # Recreate FK with ondelete SET NULL if needed in your DB state.
+        # Use the actual FK name from your database naming convention.
+
+def downgrade() -> None:
+    with op.batch_alter_table("flow_version") as batch_op:
+        batch_op.alter_column("user_id", existing_type=sa.Uuid(), nullable=False)
+        # Recreate prior FK behavior if required.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/backend/base/langflow/alembic/versions/7d327cfafab6_add_flow_history_table.py`
around lines 23 - 45, The current revision only creates flow_version.user_id as
nullable=True in upgrade() which won't change DBs that already ran this
migration; add a new Alembic revision that explicitly alters the existing column
and FK on upgraded environments: in the new migration's upgrade() use
op.alter_column("flow_version", "user_id", existing_type=sa.Uuid(),
nullable=True) and update the foreign key constraint to ensure ondelete="SET
NULL" (drop the existing FK constraint and create a new one referencing user.id
with ondelete="SET NULL"); include a corresponding downgrade() that reverts the
nullability and restores the prior FK behavior; target symbols: flow_version,
user_id, upgrade(), and the FK constraint on user_id.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@src/backend/base/langflow/alembic/versions/7d327cfafab6_add_flow_history_table.py`:
- Around line 23-45: The current revision only creates flow_version.user_id as
nullable=True in upgrade() which won't change DBs that already ran this
migration; add a new Alembic revision that explicitly alters the existing column
and FK on upgraded environments: in the new migration's upgrade() use
op.alter_column("flow_version", "user_id", existing_type=sa.Uuid(),
nullable=True) and update the foreign key constraint to ensure ondelete="SET
NULL" (drop the existing FK constraint and create a new one referencing user.id
with ondelete="SET NULL"); include a corresponding downgrade() that reverts the
nullability and restores the prior FK behavior; target symbols: flow_version,
user_id, upgrade(), and the FK constraint on user_id.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 19262dad-8676-4605-8ede-a6665f3e740c

📥 Commits

Reviewing files that changed from the base of the PR and between 902252e and 9d71c97.

📒 Files selected for processing (3)
  • src/backend/base/langflow/alembic/versions/7d327cfafab6_add_flow_history_table.py
  • src/backend/base/langflow/services/database/models/flow_version/model.py
  • src/backend/base/langflow/services/database/models/traces/model.py

@jordanrfrazier jordanrfrazier added this pull request to the merge queue Mar 5, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 5, 2026
@jordanrfrazier jordanrfrazier enabled auto-merge March 5, 2026 17:16
@jordanrfrazier jordanrfrazier disabled auto-merge March 5, 2026 17:16
@jordanrfrazier jordanrfrazier enabled auto-merge March 5, 2026 17:21
@jordanrfrazier jordanrfrazier disabled auto-merge March 5, 2026 17:22
@jordanrfrazier jordanrfrazier enabled auto-merge March 5, 2026 17:37
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 5, 2026
@jordanrfrazier jordanrfrazier enabled auto-merge March 5, 2026 20:34
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 5, 2026
@jordanrfrazier jordanrfrazier added this pull request to the merge queue Mar 5, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 5, 2026
@jordanrfrazier jordanrfrazier added this pull request to the merge queue Mar 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 6, 2026
@jordanrfrazier jordanrfrazier added this pull request to the merge queue Mar 6, 2026
@jordanrfrazier jordanrfrazier removed this pull request from the merge queue due to a manual request Mar 6, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 6, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 6, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 6, 2026
@jordanrfrazier jordanrfrazier enabled auto-merge March 6, 2026 15:58
@jordanrfrazier jordanrfrazier added this pull request to the merge queue Mar 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 6, 2026
@jordanrfrazier jordanrfrazier added this pull request to the merge queue Mar 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 6, 2026
@jordanrfrazier jordanrfrazier added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit f75b307 Mar 6, 2026
99 of 100 checks passed
@jordanrfrazier jordanrfrazier deleted the on-delete-flow-version branch March 6, 2026 17:36
HimavarshaVS pushed a commit that referenced this pull request Mar 10, 2026
* Add ondelete flag to fk in flow version table

* set uuid nullable

* Fix alembic chain for cascade migration in release branch

* Add merge migration

* correct down path

* use randomly generated reivison id

* Add expand

* update doc

* update merge migration points
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants