{"record":{"id":"1b99356bfded5b80","repo":"NanmiCoder/MediaCrawler","slug":"unsupported-database-type-db-type","errorCode":null,"errorMessage":"Unsupported database type: {db_type}","messagePattern":"Unsupported database type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"database/db_session.py","lineNumber":70,"sourceCode":"\ndef get_async_engine(db_type: str = None):\n    if db_type is None:\n        db_type = config.SAVE_DATA_OPTION\n\n    if db_type in _engines:\n        return _engines[db_type]\n\n    if db_type in [\"json\", \"jsonl\", \"csv\"]:\n        return None\n\n    if db_type == \"sqlite\":\n        db_url = f\"sqlite+aiosqlite:///{sqlite_db_config['db_path']}\"\n    elif db_type == \"mysql\" or db_type == \"db\":\n        db_url = f\"mysql+asyncmy://{mysql_db_config['user']}:{mysql_db_config['password']}@{mysql_db_config['host']}:{mysql_db_config['port']}/{mysql_db_config['db_name']}\"\n    elif db_type == \"postgres\":\n        db_url = f\"postgresql+asyncpg://{postgres_db_config['user']}:{postgres_db_config['password']}@{postgres_db_config['host']}:{postgres_db_config['port']}/{postgres_db_config['db_name']}\"\n    else:\n        raise ValueError(f\"Unsupported database type: {db_type}\")\n\n    engine = create_async_engine(db_url, echo=False)\n    _engines[db_type] = engine\n    return engine\n\n\nasync def create_tables(db_type: str = None):\n    if db_type is None:\n        db_type = config.SAVE_DATA_OPTION\n    await create_database_if_not_exists(db_type)\n    engine = get_async_engine(db_type)\n    if engine:\n        async with engine.begin() as conn:\n            await conn.run_sync(Base.metadata.create_all)\n\n\n@asynccontextmanager\nasync def get_session() -> AsyncSession:","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/database/db_session.py#L52-L88","documentation":"ValueError from database/db_session.py get_async_engine when db_type matches none of the supported backends: cached engines, the file-based trio ['json','jsonl','csv'] (which return None), 'sqlite', 'mysql'/'db', or 'postgres'. The string is used both to build the SQLAlchemy async URL and to select the engine, so an unknown value cannot be mapped to a driver.","triggerScenarios":"SAVE_DATA_OPTION / db_type set to a typo ('mongo' is handled elsewhere as a document store but not by this engine function, 'postgresql' instead of 'postgres', 'MySQL' capitalized); passing a backend name that only exists in a different version of the project.","commonSituations":"Editing SAVE_DATA_OPTION in config/base_config.py; adding a new storage backend without touching db_session; case-sensitive literals ('sqlite' vs 'SQLite') copied from docs.","solutions":["Set db_type/SAVE_DATA_OPTION to one of the exact literals: 'sqlite', 'mysql' (or 'db'), 'postgres', or 'json'/'jsonl'/'csv'.","For MongoDB use the project's MongoDB store path rather than get_async_engine, which only builds SQL engines.","Use the literal 'postgres', not 'postgresql', for the URL branch to match.","Validate the config value at startup and fail fast with the list of supported types."],"exampleFix":"# before\nget_async_engine('postgresql')\n\n# after\nget_async_engine('postgres')","handlingStrategy":"type-guard","validationCode":"SUPPORTED = {'sqlite', 'mysql', 'db', 'postgres', 'json', 'jsonl', 'csv'}\nif db_type not in SUPPORTED:\n    raise SystemExit(f'db type must be one of {sorted(SUPPORTED)}, got {db_type!r}')","typeGuard":"def is_supported_db(t: str) -> bool:\n    return isinstance(t, str) and t in {'sqlite', 'mysql', 'db', 'postgres', 'json', 'jsonl', 'csv'}","tryCatchPattern":"try:\n    engine = get_async_engine(db_type)\nexcept ValueError as e:\n    logger.error(f'unsupported db {db_type!r}: {e}')\n    raise SystemExit(2)","preventionTips":["Use the literal 'postgres' (not 'postgresql') and lowercase values","Validate SAVE_DATA_OPTION before the async engine is created","Remember 'json'/'jsonl'/'csv' return None engines by design — handle that downstream"],"tags":["database","configuration","valueerror","sqlalchemy","startup"],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}