{"record":{"id":"1a83dc04c1be1669","repo":"lfnovo/open-notebook","slug":"migration-from-provider-config-failed","errorCode":null,"errorMessage":"Migration from provider config failed","messagePattern":"Migration from provider config failed","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/credentials.py","lineNumber":484,"sourceCode":"# =============================================================================\n# Migration endpoints\n# =============================================================================\n\n\n@router.post(\"/migrate-from-provider-config\")\nasync def migrate_from_provider_config():\n    \"\"\"Migrate existing ProviderConfig data to individual credential records.\"\"\"\n    try:\n        return await svc_migrate_from_provider_config()\n    except ValueError as e:\n        raise _handle_value_error(e)\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"ProviderConfig migration FAILED: {type(e).__name__}: {e}\", exc_info=True)\n        raise HTTPException(status_code=500, detail=\"Migration from provider config failed\")\n\n\n@router.post(\"/migrate-from-env\")\nasync def migrate_from_env():\n    \"\"\"Migrate API keys from environment variables to credential records.\"\"\"\n    try:\n        return await svc_migrate_from_env()\n    except ValueError as e:\n        raise _handle_value_error(e)\n    except HTTPException:\n        raise\n    except OpenNotebookError:\n        raise\n    except Exception as e:\n        logger.error(f\"Env migration FAILED: {type(e).__name__}: {e}\", exc_info=True)\n        raise HTTPException(status_code=500, detail=\"Migration from environment variables failed\")\n","sourceCodeStart":466,"sourceCodeEnd":501,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/credentials.py#L466-L501","documentation":"Catch-all 500 from POST /api/credentials/migrate-from-provider-config. This one-shot migration converts legacy ProviderConfig records into credential records; any unexpected failure (DB access, record shape mismatch, partial state) aborts with this error.","triggerScenarios":"Running the migration when legacy provider config records exist but are malformed (older schema), when the DB is unavailable, or when a previous partial migration left inconsistent state.","commonSituations":"Upgrading an older Open Notebook install that stored provider config in a different table shape, running the migration twice after a partial failure, or env/DB drift during upgrade.","solutions":["Check logs for 'ProviderConfig migration FAILED: <ExceptionType>: ...' with full traceback (exc_info=True)","Back up the database before retrying a migration; inspect partially created credential records","Fix or remove malformed legacy ProviderConfig records identified in the traceback","Retry the migration after resolving the root cause; verify results via GET /api/credentials"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// snapshot before one-shot migrations\nawait backupDatabase(); // export SurrealDB data first","typeGuard":null,"tryCatchPattern":"try {\n  await api.migrateFromProviderConfig();\n} catch (e) {\n  if (e.status === 500) {\n    // check logs for 'ProviderConfig migration FAILED' traceback; audit partially created credentials\n    await auditCredentials();\n  }\n  throw e;\n}","preventionTips":["Back up the DB before any migration endpoint call","Never re-run a failed migration without auditing partial results"],"tags":["credentials","migration","provider-config","http-500"],"backgroundTag":"data-migration-failed","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}