{"record":{"id":"2a727d98a98442c8","repo":"zylon-ai/private-gpt","slug":"db2-database-query-dependencies-are-not-installed","errorCode":null,"errorMessage":"DB2 database query dependencies are not installed. Install with one of: `uv sync --inexact --extra database-db2` or `uv sync --inexact --extra database`.","messagePattern":"DB2 database query dependencies are not installed\\. Install with one of: `uv sync --inexact --extra database-db2` or `uv sync --inexact --extra database`\\.","errorType":"exception","errorClass":"ImportError","httpStatus":400,"severity":"error","filePath":"private_gpt/components/database/connection_factory.py","lineNumber":49,"sourceCode":"    \"mysql\": DatabaseDialect.MYSQL,\n    \"mssql\": DatabaseDialect.MSSQL,\n    \"microsoft\": DatabaseDialect.MSSQL,\n    \"db2\": DatabaseDialect.DB2,\n    \"ibm_db_sa\": DatabaseDialect.DB2,\n}\n\n_URL_PASSWORD_RE = re.compile(r\"(://[^:/?#@]+:)([^@/?#]+)(@)\")\n_DB2_BRACED_PWD_RE = re.compile(r\"(PWD=)\\{((?:[^}]|}})*)\\}(;)\", re.IGNORECASE)\n_DB2_PLAIN_PWD_RE = re.compile(r\"(PWD=)(?!\\{)([^;]*)(;)\", re.IGNORECASE)\n_DB2_VALUE_NEEDS_ESCAPING_RE = re.compile(r\"[;{}]|^\\s|\\s$\")\n\n\n@functools.cache\ndef _load_ibm_db_dbi() -> Any:\n    try:\n        import ibm_db_dbi  # type: ignore[import-not-found,import-untyped]\n    except ImportError as e:\n        raise ImportError(\n            format_missing_dependency_message(\n                \"DB2 database query\",\n                extras=(\"database-db2\", \"database\"),\n            )\n        ) from e\n\n    return ibm_db_dbi\n\n\ndef classify_dialect(dialect_name: str | None) -> DatabaseDialect:\n    \"\"\"Classify a dialect/scheme identifier into a DatabaseDialect.\"\"\"\n    return _DIALECT_NAME_MAP.get((dialect_name or \"\").lower(), DatabaseDialect.UNKNOWN)\n\n\ndef is_db2_connection_string(connection_string: str) -> bool:\n    \"\"\"Whether a SQLAlchemy-style connection string targets DB2.\"\"\"\n    scheme = connection_string.split(\"://\", 1)[0].split(\"+\", 1)[0]\n    return classify_dialect(scheme) is DatabaseDialect.DB2","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/database/connection_factory.py#L31-L67","documentation":"ImportError raised by the cached loader _load_ibm_db_dbi when the ibm_db_dbi driver is missing. It is raised lazily on first DB2 connection attempt and chained from the original ImportError, with a message telling you exactly which uv extras provide the driver: database-db2 (DB2 only) or database (all database drivers). functools.cache means the failure is remembered, so fixing the environment requires no code change, only a re-run.","triggerScenarios":"Creating a DB2 connection through connection_factory with a db2://... URL (or a dialect classified as DB2) when the ibm_db_dbi package is not importable in the current virtualenv.","commonSituations":"Running with a minimal dependency set (no database extra); a fresh environment after switching from pip/poetry to uv; CI cache restored without the db2 extra; system-level ibm_db driver libs missing so the Python package fails to import.","solutions":["Run: uv sync --inexact --extra database-db2 (or --extra database for all drivers)","Verify with: python -c \"import ibm_db_dbi\" in the same environment the app runs in","If the import still fails after install, check the underlying chained ImportError for missing OS-level DB2 client libraries and install those","Ensure you are not running in a different virtualenv/conda env than the one you synced"],"exampleFix":"# before: raises ImportError on first DB2 query\n# after\n# uv sync --inexact --extra database-db2\nconn = connection_factory.create(db2_url)","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec('ibm_db_dbi') is None:\n    raise SystemExit('DB2 driver missing; run: uv sync --inexact --extra database-db2')","typeGuard":null,"tryCatchPattern":"try:\n    conn = connection_factory.create(db2_url)\nexcept ImportError as e:\n    if 'database-db2' in str(e):\n        raise SystemExit('DB2 driver missing; run: uv sync --inexact --extra database-db2') from e\n    raise","preventionTips":["Declare the database-db2 (or database) extra in deployment images, not just locally","Smoke-test required drivers at container start with importlib.util.find_spec","Keep app and sync in the same virtualenv; verify with python -c 'import ibm_db_dbi'"],"tags":["database","db2","dependencies","import","installation"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}