Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class SpanTable(SpanBase, table=True): # type: ignore[call-arg]
__tablename__ = "span"

id: UUID = Field(default_factory=uuid4, primary_key=True)
trace_id: UUID = Field(foreign_key="trace.id", index=True, description="Parent trace ID")
trace_id: UUID = Field(foreign_key="trace.id", ondelete="CASCADE", index=True, description="Parent trace ID")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Find migrations that touch the span->trace FK behavior
rg -n -C3 'span_trace_id_fkey|span\.trace_id|trace\.id|ON DELETE CASCADE|on delete cascade|create_foreign_key|drop_constraint' \
  src/backend/base/langflow/alembic/versions

# 2) List migration files for manual inspection if needed
fd . src/backend/base/langflow/alembic/versions

Repository: langflow-ai/langflow

Length of output: 30080


🏁 Script executed:

# 1. Check the exact model change at line 254
sed -n '250,260p' src/backend/base/langflow/services/database/models/traces/model.py

# 2. Search more specifically for span.trace_id FK migrations
rg -l 'span' src/backend/base/langflow/alembic/versions/ | xargs grep -l 'trace_id.*ondelete\|ondelete.*trace_id\|span.*trace.*CASCADE'

# 3. Check if there are any migrations specifically mentioning "span" table updates for trace_id
fd . src/backend/base/langflow/alembic/versions/ --exec grep -l 'batch_alter_table.*span' {} \;

Repository: langflow-ai/langflow

Length of output: 528


🏁 Script executed:

# Check the initial span table creation migration to see if CASCADE was already there
cat src/backend/base/langflow/alembic/versions/3478f0bd6ccb_add_trace_and_span_tables.py | head -100

# Also check if there are any subsequent migrations that alter the span table
fd . src/backend/base/langflow/alembic/versions/ --exec grep -l 'batch_alter_table.*"span"' {} \;

Repository: langflow-ai/langflow

Length of output: 4783


🏁 Script executed:

# Check all migrations that alter the span table
cd src/backend/base/langflow/alembic/versions && for file in *.py; do
  if grep -q 'batch_alter_table.*"span"' "$file"; then
    echo "=== $file ==="
    grep -A 10 'batch_alter_table.*"span"' "$file" | head -20
  fi
done

Repository: langflow-ai/langflow

Length of output: 1080


Add an Alembic migration for the span.trace_id FK CASCADE change

The model change at line 254 adds ondelete="CASCADE" to the foreign key definition, but this only affects new database instances. Existing PostgreSQL databases will retain the original constraint without CASCADE until an explicit Alembic migration updates it.

Create a migration that drops and recreates the span.trace_id foreign key constraint with ON DELETE CASCADE, following the pattern used in migration 0e6138e7a0c2_add_ondelete_cascade_to_file_user_id_fk.py.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/backend/base/langflow/services/database/models/traces/model.py` at line
254, Add an Alembic migration to update the existing PostgreSQL foreign key for
span.trace_id to include ON DELETE CASCADE: create a new revision that in
upgrade() drops the current FK constraint on the span.trace_id column and
recreates it with ON DELETE CASCADE, and in downgrade() reverses that by
dropping the CASCADE FK and recreating the original FK without ON DELETE; follow
the same pattern and naming conventions used in migration
0e6138e7a0c2_add_ondelete_cascade_to_file_user_id_fk.py and target the
span.trace_id constraint referenced by the model change (trace_id: UUID Field
with foreign_key="trace.id", ondelete="CASCADE").

parent_span_id: UUID | None = Field(
default=None,
foreign_key="span.id",
Expand Down
Loading