{"record":{"id":"076f976b2fb49e47","repo":"lfnovo/open-notebook","slug":"migration-from-environment-variables-failed","errorCode":null,"errorMessage":"Migration from environment variables failed","messagePattern":"Migration from environment variables failed","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"api/routers/credentials.py","lineNumber":500,"sourceCode":"    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":482,"sourceCodeEnd":501,"githubUrl":"https://github.com/lfnovo/open-notebook/blob/a7de90d38aaf18ee85fd661854d35c11e44613e2/api/routers/credentials.py#L482-L501","documentation":"Catch-all 500 from POST /api/credentials/migrate-from-env. This migration reads provider API keys from environment variables and creates credential records; failures reading env vars, or DB write errors during creation, produce this 500.","triggerScenarios":"Running migrate-from-env when the API process env lacks expected provider variables, when env var values are malformed, or when writing the resulting credential records fails (DB down, encryption key missing).","commonSituations":"OPEN_NOTEBOOK_ENCRYPTION_KEY unset so new credentials cannot be encrypted, migrating on a fresh install where DB schema hasn't been created yet, or env vars loaded inconsistently (shell vs docker-compose).","solutions":["Check logs for 'Env migration FAILED: <ExceptionType>: ...' with traceback","Verify OPEN_NOTEBOOK_ENCRYPTION_KEY and provider API key env vars are visible to the API process (not just your shell)","Ensure the DB is up and schema migrations ran (restart the API)","Retry the migration; existing provider env keys that already migrated are typically skipped or can be deduped after"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// confirm env is visible to the API process before migrating\nconst status = await api.getEnvStatus(); // or verify env vars server-side\nif (!status?.encryptionConfigured) throw new Error('Set OPEN_NOTEBOOK_ENCRYPTION_KEY before migrating');","typeGuard":null,"tryCatchPattern":"try {\n  await api.migrateFromEnv();\n} catch (e) {\n  if (e.status === 500) showError('Env migration failed — check API logs and required env vars');\n  throw e;\n}","preventionTips":["Set OPEN_NOTEBOOK_ENCRYPTION_KEY before running env migration","Ensure provider env vars are present in the API/worker process (docker-compose env, not just shell)"],"tags":["credentials","migration","env-vars","http-500"],"backgroundTag":"data-migration-failed","analyzedSha":"a7de90d38aaf18ee85fd661854d35c11e44613e2","analyzedAt":"2026-08-27T02:39:58.166Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}