{"record":{"id":"5656436ce127c30a","repo":"iflytek/astron-agent","slug":"redis-address-is-not-set-in-environment-variables-database","errorCode":null,"errorMessage":"Redis address is not set in environment variables","messagePattern":"Redis address is not set in environment variables","errorType":"console","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/plugin/link/extensions/database_migration.py","lineNumber":91,"sourceCode":"    config = Config(str(alembic_ini))\n    config.set_main_option(\"script_location\", str(alembic_dir))\n    return config\n\n\ndef _get_or_create_redis_service() -> RedisService:\n    \"\"\"Get or create Redis service instance.\"\"\"\n    redis_service = get_redis_engine()\n    if redis_service is not None:\n        logging.info(\"redis_service is successfully got from get_redis_engine()\")\n        return redis_service\n\n    redis_addr = os.getenv(const.REDIS_CLUSTER_ADDR_KEY) or os.getenv(\n        const.REDIS_ADDR_KEY\n    )\n    redis_password = os.getenv(const.REDIS_PASSWORD_KEY)\n    if not redis_addr:\n        logging.error(\"Redis address is not set in environment variables\")\n        raise ValueError(\"Redis address is not set in environment variables\")\n\n    return RedisService(cluster_addr=redis_addr, password=redis_password)\n\n\ndef _handle_migration_error(config: Config, error: OperationalError) -> None:\n    \"\"\"Handle migration operational errors.\"\"\"\n    db_error_code = getattr(error.orig, \"args\", [None])[0]\n\n    if db_error_code in (\n        MYSQL_ERROR_SELECT_DENIED,\n        MYSQL_ERROR_ACCESS_DENIED,\n        MYSQL_ERROR_EXECUTE_DENIED,\n    ):\n        logging.warning(\n            f\"Skip database migration due to insufficient permissions: {error}\"\n        )\n        return\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/link/extensions/database_migration.py#L73-L109","documentation":"_get_or_create_redis_service needs a Redis address to construct a RedisService for migration support. It reads REDIS_CLUSTER_ADDR_KEY first, falling back to REDIS_ADDR_KEY, and also reads REDIS_PASSWORD_KEY. If neither address variable is set (or empty) it raises ValueError 'Redis address is not set in environment variables'.","triggerScenarios":"Running run_database_migration in an environment where neither the cluster-address nor the standalone-address Redis env var is defined, regardless of whether the password is set.","commonSituations":"Deploying without Redis config in .env/Helm values; REDIS_CLUSTER_ADDR removed in favor of REDIS_ADDR (or vice versa) after an upgrade; typo'd env var names in the deployment manifest; running migrations locally without the infrastructure env file.","solutions":["Set REDIS_CLUSTER_ADDR (preferred) or REDIS_ADDR in the environment before running the migration","Verify the deployment manifest / compose file exports the exact env key names expected by const.py","Check for renamed keys after upgrades and update configs to the current const names","Optionally set REDIS_PASSWORD too if the Redis instance requires auth"],"exampleFix":"// before (.env)\n# no redis config\n// after (.env)\nREDIS_CLUSTER_ADDR=127.0.0.1:6379\nREDIS_PASSWORD=secret","handlingStrategy":"validation","validationCode":"import os\ndef has_redis_addr() -> bool:\n    return bool(os.getenv(\"REDIS_CLUSTER_ADDR\") or os.getenv(\"REDIS_ADDR\"))","typeGuard":null,"tryCatchPattern":"try:\n    run_database_migration()\nexcept ValueError as e:\n    if \"Redis address\" in str(e):\n        sys.exit(f\"Config error: {e}\")\n    raise","preventionTips":["Set REDIS_CLUSTER_ADDR (or REDIS_ADDR) in every environment that runs migrations","Mirror the exact const.py key names in deployment manifests to avoid typos","Add a pre-flight env validation step to startup scripts and CI","Include REDIS_PASSWORD when auth is enabled to avoid follow-on auth failures"],"tags":["redis","environment","configuration","migration"],"backgroundTag":"missing-env-var","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}