{"record":{"id":"a27e9ecac2206196","repo":"zylon-ai/private-gpt","slug":"redis-cache-dependencies-are-not-installed-instal","errorCode":null,"errorMessage":"Redis cache dependencies are not installed. Install with `uv sync --inexact --extra redis`.","messagePattern":"Redis cache dependencies are not installed\\. Install with `uv sync --inexact --extra redis`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/cache/cache_service.py","lineNumber":80,"sourceCode":"        cache_key = self._key(namespace, key)\n        expires_at = time.monotonic() + ttl_seconds if ttl_seconds is not None else None\n        with self._lock:\n            self._values[cache_key] = (expires_at, value)\n            self._values.move_to_end(cache_key)\n            while len(self._values) > self._max_entries:\n                self._values.popitem(last=False)\n\n    def delete(self, namespace: str, key: str) -> None:\n        with self._lock:\n            self._values.pop(self._key(namespace, key), None)\n\n\nclass RedisCache:\n    def __init__(self, settings: Settings) -> None:\n        try:\n            import redis\n        except ImportError as error:\n            raise ImportError(\n                format_missing_dependency_message(\"Redis cache\", extras=\"redis\")\n            ) from error\n\n        redis_database = (\n            settings.cache.redis_database\n            if settings.cache.redis_database is not None\n            else int(settings.redis.database or 0)\n        )\n        self._prefix = settings.cache.key_prefix\n        self._client = redis.Redis.from_url(\n            settings.redis.url,\n            db=redis_database,\n            decode_responses=False,\n        )\n\n    def _key(self, namespace: str, key: str) -> str:\n        digest = hashlib.sha256(key.encode()).hexdigest()\n        return f\"{self._prefix}:{namespace}:{digest}\"","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/cache/cache_service.py#L62-L98","documentation":"ImportError raised by RedisCache.__init__ (private_gpt/components/cache/cache_service.py) when the optional `redis` Python package is not installed. The cache extra is decoupled from the base install; constructing RedisCache with cache settings pointing at Redis lazily imports redis and re-raises with an install instruction from format_missing_dependency_message.","triggerScenarios":"Setting PGPT_SETTINGS cache backend/type to redis (or a profile enabling RedisCache) without having run an extra-enabled install; calling RedisCache(settings) in tests on a base-install environment.","commonSituations":"Switching from in-memory/LRUCache to redis in settings.yaml without reinstalling dependencies; fresh clones deployed with plain `uv sync` (exact) which drops extras after a lock change; CI environments not passing the redis extra.","solutions":["Install the extra exactly as the message says: `uv sync --inexact --extra redis`.","With pip: `pip install 'private-gpt[redis]'` or `pip install redis`.","If Redis is not intended, revert the cache settings to the memory backend so RedisCache is never constructed.","Ensure deployment Dockerfiles/CI include the redis extra."],"exampleFix":"// before\n# settings: cache backend = redis, base install\ncache = RedisCache(settings)  # ImportError\n\n// after\n$ uv sync --inexact --extra redis\ncache = RedisCache(settings)","handlingStrategy":"validation","validationCode":"try:\n    import redis  # noqa: F401\n    HAS_REDIS = True\nexcept ImportError:\n    HAS_REDIS = False\n\nif settings.cache.backend == \"redis\" and not HAS_REDIS:\n    raise RuntimeError(\"Run `uv sync --inexact --extra redis` before enabling the redis cache\")","typeGuard":null,"tryCatchPattern":"try:\n    cache = RedisCache(settings)\nexcept ImportError as e:\n    raise RuntimeError(\"Install the redis extra: uv sync --inexact --extra redis\") from e","preventionTips":["Sync extras whenever you enable redis cache settings.","Beware exact `uv sync` pruning extras after lock changes — use --inexact.","Include extras in Dockerfile/CI install steps.","Fail fast at startup with an import probe rather than at first request."],"tags":["dependencies","optional-extra","redis","cache","installation"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}