lfnovo/open-notebook · error · HTTPException

Migration from provider config failed

Error message

Migration from provider config failed

What it means

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.

Source

Thrown at api/routers/credentials.py:484

# =============================================================================
# Migration endpoints
# =============================================================================


@router.post("/migrate-from-provider-config")
async def migrate_from_provider_config():
    """Migrate existing ProviderConfig data to individual credential records."""
    try:
        return await svc_migrate_from_provider_config()
    except ValueError as e:
        raise _handle_value_error(e)
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"ProviderConfig migration FAILED: {type(e).__name__}: {e}", exc_info=True)
        raise HTTPException(status_code=500, detail="Migration from provider config failed")


@router.post("/migrate-from-env")
async def migrate_from_env():
    """Migrate API keys from environment variables to credential records."""
    try:
        return await svc_migrate_from_env()
    except ValueError as e:
        raise _handle_value_error(e)
    except HTTPException:
        raise
    except OpenNotebookError:
        raise
    except Exception as e:
        logger.error(f"Env migration FAILED: {type(e).__name__}: {e}", exc_info=True)
        raise HTTPException(status_code=500, detail="Migration from environment variables failed")

View on GitHub (pinned to a7de90d38a)

Solutions

  1. Check logs for 'ProviderConfig migration FAILED: <ExceptionType>: ...' with full traceback (exc_info=True)
  2. Back up the database before retrying a migration; inspect partially created credential records
  3. Fix or remove malformed legacy ProviderConfig records identified in the traceback
  4. Retry the migration after resolving the root cause; verify results via GET /api/credentials
Defensive patterns

Strategy: try-catch

Validate before calling

// snapshot before one-shot migrations
await backupDatabase(); // export SurrealDB data first

Try / catch

try {
  await api.migrateFromProviderConfig();
} catch (e) {
  if (e.status === 500) {
    // check logs for 'ProviderConfig migration FAILED' traceback; audit partially created credentials
    await auditCredentials();
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of lfnovo/open-notebook@a7de90d38a (2026-08-27). Data as JSON: /api/errors/1a83dc04c1be1669. Report an issue: GitHub.