langflow-ai/langflow · error · HTTPException

Flow data could not be copied for snapshot. The data may be

Error message

Flow data could not be copied for snapshot. The data may be corrupted.

What it means

422 from POST /flows/{flow_id}/versions/ (create_snapshot): after the WRITE-permission check on the flow, copy.deepcopy(flow.data) raised. flow.data is stored as JSON; if the persisted structure contains objects deepcopy cannot duplicate (non-picklable or recursive structures injected via a custom DB write), the snapshot aborts before any version row is created.

Source

Thrown at src/backend/base/langflow/api/v1/flow_version.py:218

    current_user: CurrentActiveUser,
    session: DbSession,
    body: FlowVersionCreate | None = None,
) -> FlowVersionRead:
    flow = await _get_user_flow(session, flow_id, current_user.id)
    await ensure_flow_permission(
        current_user,
        FlowAction.WRITE,
        flow_id=flow.id,
        flow_user_id=flow.user_id,
        workspace_id=flow.workspace_id,
        folder_id=flow.folder_id,
    )
    description = body.description if body else None

    try:
        data = copy.deepcopy(flow.data)
    except Exception as exc:
        raise HTTPException(
            status_code=422,
            detail="Flow data could not be copied for snapshot. The data may be corrupted.",
        ) from exc

    try:
        entry = await create_flow_version_entry(
            session,
            flow_id=flow.id,
            user_id=current_user.id,
            data=data,
            description=description,
        )
    except FlowVersionError as exc:
        raise _translate_version_error(exc) from exc
    return _version_to_read(entry)


@router.post("/{version_id}/activate")

View on GitHub (pinned to 976ec789d2)

Solutions

  1. GET the flow and inspect flow.data for anomalies (self-references, absurd nesting) — fix or re-save the flow from the UI so data is normalised
  2. If the flow opens in the UI, make any small edit and save to rewrite data cleanly, then snapshot
  3. As a last resort recreate the flow from its exported JSON
Defensive patterns

Strategy: try-catch

Validate before calling

const flow = (await axios.get(`/api/v1/flows/${flowId}`)).data;
const snapshotSafe = flow.data == null || typeof flow.data === 'object'; // shallow sanity only

Type guard

const isPlainFlowData = (d: unknown): d is Record<string, unknown> =>
  d === null || (typeof d === 'object' && !Array.isArray(d));

Try / catch

catch (e) {
  if (e.response?.status === 422 && /could not be copied/.test(e.response.data?.detail))
    notifyCorruptFlowData();
  throw e;
}

Prevention

When it happens

Trigger: Creating a snapshot when flow.data was corrupted or hand-modified in the database — e.g. directly-uploaded flow rows containing deeply recursive dicts or exotic types — so deepcopy fails.

Common situations: Flows imported from external tooling that wrote non-standard JSON structures into flow.data; databases restored from partially-serialized dumps; extremely unusual data inserted via raw SQL.

Related errors


AI-assisted analysis of langflow-ai/langflow@976ec789d2 (2026-08-14). Data as JSON: /api/errors/fb54952bdbaa37cf. Report an issue: GitHub.