Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 15 additions & 4 deletions src/backend/base/langflow/alembic/migration_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,20 @@ def _check_downgrade_safety(self, node: ast.FunctionDef, phase: MigrationPhase)
warnings = []

# Check if downgrade might lose data

# Optimization: Unparse node only once & cache all comparisons for all matching ast.Call children.
op_calls = []
for child in ast.walk(node):
if isinstance(child, ast.Call) and self._is_op_call(child, "alter_column"):
# Check if there's a backup mechanism
func_content = ast.unparse(node)
if "backup" not in func_content.lower() and "SELECT" not in func_content:
op_calls.append(child)

if op_calls:
# ast.unparse is extremely expensive; only call once per function
func_content = ast.unparse(node)
func_content_lower = func_content.lower()
backup_not_present = "backup" not in func_content_lower and "SELECT" not in func_content
if backup_not_present:
for child in op_calls:
warnings.append(
Violation(
"UNSAFE_ROLLBACK",
Expand All @@ -229,7 +238,9 @@ def _check_downgrade_safety(self, node: ast.FunctionDef, phase: MigrationPhase)

# CONTRACT phase special handling
if phase == MigrationPhase.CONTRACT:
func_content = ast.unparse(node)
# ast.unparse is already done if above, else do once here
if not op_calls:
func_content = ast.unparse(node)
if "NotImplementedError" not in func_content and "raise" not in func_content:
warnings.append(
Violation(
Expand Down
2 changes: 1 addition & 1 deletion src/lfx/src/lfx/_assets/component_index.json

Large diffs are not rendered by default.

Loading