Skip to content

fix: add ondelete=CASCADE to TraceBase.flow_id to match migration#12001

Closed
RamGopalSrikar wants to merge 2 commits into
mainfrom
fix/trace-model-ondelete-cascade
Closed

fix: add ondelete=CASCADE to TraceBase.flow_id to match migration#12001
RamGopalSrikar wants to merge 2 commits into
mainfrom
fix/trace-model-ondelete-cascade

Conversation

@RamGopalSrikar
Copy link
Copy Markdown
Contributor

@RamGopalSrikar RamGopalSrikar commented Mar 3, 2026

Summary

  • Adds ondelete="CASCADE" to TraceBase.flow_id field to match the migration definition
  • Fixes migration validator mismatch that blocked backend startup

Problem

The migration file 3478f0bd6ccb_add_trace_and_span_tables.py creates the trace table's flow_id foreign key with ondelete="CASCADE", but the model was missing this parameter. This caused the migration validator to detect a mismatch and block startup with:

There's a mismatch between the models and the database.
New upgrade operations detected: [('remove_fk', ..., ondelete='CASCADE', ...), ('add_fk', ...)]

Test plan

  • Run make backend and verify no migration mismatch errors
  • Verify traces are deleted when their parent flow is deleted

Summary by CodeRabbit

  • Bug Fixes
    • Improved data consistency by automatically removing associated traces when a flow is deleted, preventing orphaned records in the database.

The migration file creates the trace table's flow_id foreign key with
ondelete="CASCADE", but the model was missing this parameter. This
mismatch caused the migration validator to block startup.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a18aaa and 075445d.

📒 Files selected for processing (1)
  • src/backend/base/langflow/services/database/models/traces/model.py

Walkthrough

Added cascade delete behavior to the flow_id foreign key in the TraceBase database model. When a flow is deleted, all associated traces will now be automatically deleted via the database constraint rather than requiring explicit application logic.

Changes

Cohort / File(s) Summary
Database Model Update
src/backend/base/langflow/services/database/models/traces/model.py
Added ondelete="CASCADE" parameter to the flow_id foreign key field in TraceBase class to enforce automatic cascade deletion of traces when their parent flow is deleted.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes


Important

Pre-merge checks failed

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

❌ Failed checks (1 error, 2 warnings)

Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error PR adds CASCADE deletion but lacks regression tests to verify trace deletion behavior when parent flows are deleted. Add regression tests verifying cascade deletion: create flow/traces, delete flow, confirm traces deleted automatically, and validate model parameter matches migration expectations.
Test Quality And Coverage ⚠️ Warning PR introduces CASCADE foreign key constraint but lacks database-level tests validating cascade deletion behavior. Add integration test following test_sso_models.py pattern to verify traces auto-delete when flows are deleted via CASCADE constraint.
Test File Naming And Structure ⚠️ Warning Test coverage for ondelete="CASCADE" feature is insufficient; cascade deletion behavior is not verified in tests. Add assertions verifying flow_id field includes ondelete="CASCADE" and create integration tests validating cascade deletion when parent flow is deleted.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding ondelete=CASCADE to TraceBase.flow_id to match a migration file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Excessive Mock Usage Warning ✅ Passed PR only modifies database model without adding or changing test files, making mock usage assessment not applicable.
✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/trace-model-ondelete-cascade

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 the community Pull Request from an external contributor label Mar 3, 2026
@github-actions github-actions Bot added the bug Something isn't working label Mar 3, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 3, 2026
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Mar 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 3, 2026

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 23%
22.87% (7981/34889) 15.45% (4224/27334) 15.6% (1147/7348)

Unit Test Results

Tests Skipped Failures Errors Time
2611 0 💤 0 ❌ 0 🔥 42.878s ⏱️

Copy link
Copy Markdown
Collaborator

@olayinkaadelakun olayinkaadelakun left a comment

Choose a reason for hiding this comment

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

I pulled an old branch and checkout this branch ad there were no migration issues

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

codecov Bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.31%. Comparing base (5a18aaa) to head (075445d).
⚠️ Report is 12 commits behind head on main.

❌ Your project status has failed because the head coverage (42.29%) 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   #12001      +/-   ##
==========================================
- Coverage   37.32%   37.31%   -0.01%     
==========================================
  Files        1592     1592              
  Lines       78279    78279              
  Branches    11824    11824              
==========================================
- Hits        29216    29209       -7     
- Misses      47442    47449       +7     
  Partials     1621     1621              
Flag Coverage Δ
backend 57.32% <100.00%> (-0.04%) ⬇️
frontend 20.49% <ø> (ø)
lfx 42.29% <ø> (ø)

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

Files with missing lines Coverage Δ
.../langflow/services/database/models/traces/model.py 90.06% <100.00%> (ø)

... and 8 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.

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

@Adam-Aghili Adam-Aghili left a comment

Choose a reason for hiding this comment

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

LGTM!
Thank you for catching this work with @RamGopalSrikar to reproduce locally on my machine.

Merge once script is uploaded. Make sure to carry over the new change to the RC branch PR

@Cristhianzl Cristhianzl 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
Copy link
Copy Markdown
Collaborator

adding in #12059

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working community Pull Request from an external contributor lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants