fix(api): stop workspace import dropping every workflow variable - #6002
Conversation
The workspace importer guarded its variable write on `Array.isArray`, but `parseWorkflowVariables` — what the matching workspace export emits — returns the record form. Every variable was silently dropped, so exporting a workspace and importing it back lost all of them. It now uses the shared `normalizeImportedVariables`, which accepts both shapes. Also runs the workspace importer through `prepareWorkflowStateForPersistence`, the pipeline the editor, the v1 import API and the single-workflow admin import already share. Without it this route wrote raw parsed state, so a dangling edge tripped the `workflow_edges` foreign key and failed the restore, and blocks missing their backfilled columns could land unopenable. Repoints `persistImportedWorkflow` at the same helper, removing the last inline copy — all four import paths now normalize variables identically. Adds the first tests for these helpers, including the export -> import round trip that pins the record form the bug dropped.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Workspace import now runs workflow state through In-app import ( Adds Vitest coverage for Reviewed by Cursor Bugbot for commit d70825a. Configure here. |
Greptile SummaryFixes workspace import silently dropping workflow variables and skipping shared state normalization.
Confidence Score: 5/5Safe to merge; the change closes a real silent data-loss path and matches established import pipelines without introducing a new failure mode. Shared helpers already used by other import paths; prepare-state does not own variables, and normalizeImportedVariables accepts the record form exports emit while hardening types and ids.
|
| Filename | Overview |
|---|---|
| apps/sim/app/api/v1/admin/workspaces/[id]/import/route.ts | Applies shared prepare-state and variable normalization so workspace restore keeps variables and valid graph state. |
| apps/sim/lib/workflows/operations/import-export.ts | Replaces inline variable conversion in persistImportedWorkflow with normalizeImportedVariables. |
| apps/sim/lib/workflows/variables/parse.test.ts | New tests cover both variable shapes, edge cases, and the export→import regression. |
Reviews (1): Last reviewed commit: "fix(api): stop workspace import dropping..." | Re-trigger Greptile
Summary
Follow-up to #5999, which extracted the shared import helpers. This applies them to the last path that was still hand-rolling its own — and that path had a real data-loss bug.
Array.isArray, butparseWorkflowVariables— what the matching workspace export emits — returns the record form. So export a workspace, import it back, and all variables were gone. Restore path, no warning, no error. Now uses the sharednormalizeImportedVariables, which accepts both shapes.workflow_edgesforeign key and failed the restore, and blocks missing their backfilled columns could land unopenable — the same class feat(api): add workflow export and import endpoints to the public v1 API #5999 closed elsewhere. Now callsprepareWorkflowStateForPersistence.persistImportedWorkflow(the in-app importer) at the same helper, removing the last inline copy. All four import paths now normalize variables identically.Type of Change
Testing
First tests for these helpers — 15 cases covering both shapes, JSON-string column values, missing/padded/non-string ids, unrecognized
type, a__proto__-keyed entry (built viaJSON.parse, since an object literal's__proto__sets the prototype instead), and the export → import round trip that pins the record form the bug dropped.1273 tests pass across
lib/workflows/,app/api/v1/workflows/andapp/api/workflows/. Typecheck, lint,check:api-validation:strictand the monorepo boundary check all pass.Not exercised against a live server — no real workspace was exported and re-imported end to end.
Checklist